Skip to content

Commit

Permalink
stable ssr_modes_example example
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud-eltahawy committed Apr 5, 2024
1 parent 16c73af commit 1adeba3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/ssr_modes_axum/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2024-03-31"
channel = "stable"
16 changes: 10 additions & 6 deletions examples/ssr_modes_axum/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,24 @@ fn Post() -> impl IntoView {
.map_err(|_| PostError::InvalidId)
})
};
let post = create_resource(id, |id| async move {
let post_resource = create_resource(id, |id| async move {
match id {
Err(e) => Err(e),
Ok(id) => get_post(id)
.await
.map(|data| data.ok_or(PostError::PostNotFound))
.map_err(|_| PostError::ServerError)
.flatten(),
.map_err(|_| PostError::ServerError),
}
});

let post = move || match post_resource.get() {
Some(Ok(Ok(v))) => Ok(v),
_ => Err(PostError::ServerError),
};

let post_view = move || {
post.and_then(|post| {
view! {
post().and_then(|post| {
Ok(view! {
// render content
<h1>{&post.title}</h1>
<p>{&post.content}</p>
Expand All @@ -103,7 +107,7 @@ fn Post() -> impl IntoView {
// when it's first served
<Title text=post.title.clone()/>
<Meta name="description" content=post.content.clone()/>
}
})
})
};

Expand Down
2 changes: 0 additions & 2 deletions examples/ssr_modes_axum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(result_flattening)]

pub mod app;

#[cfg(feature = "ssr")]
Expand Down

0 comments on commit 1adeba3

Please sign in to comment.