From 9adae32847a5ff8d42c541be38590690404dafc7 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 25 Aug 2023 16:00:01 -0400 Subject: [PATCH] examples: improve hackernews behavior --- examples/hackernews/src/routes/stories.rs | 24 +++--- examples/hackernews/src/routes/story.rs | 77 +++++++++---------- .../hackernews_axum/src/routes/stories.rs | 25 +++--- examples/hackernews_axum/src/routes/story.rs | 77 +++++++++---------- 4 files changed, 94 insertions(+), 109 deletions(-) diff --git a/examples/hackernews/src/routes/stories.rs b/examples/hackernews/src/routes/stories.rs index 1594bddbe..b0a7f00a8 100644 --- a/examples/hackernews/src/routes/stories.rs +++ b/examples/hackernews/src/routes/stories.rs @@ -36,8 +36,8 @@ pub fn Stories() -> impl IntoView { let (pending, set_pending) = create_signal(false); let hide_more_link = move || { - pending() - || stories.get().unwrap_or(None).unwrap_or_default().len() < 28 + stories.get().unwrap_or(None).unwrap_or_default().len() < 28 + || pending() }; view! { @@ -65,20 +65,16 @@ pub fn Stories() -> impl IntoView { }} "page " {page} - "Loading..."

} + - - - "more >" - - -
+ "more >" + +
diff --git a/examples/hackernews/src/routes/story.rs b/examples/hackernews/src/routes/story.rs index daaffa4c9..313d024f6 100644 --- a/examples/hackernews/src/routes/story.rs +++ b/examples/hackernews/src/routes/story.rs @@ -25,48 +25,45 @@ pub fn Story() -> impl IntoView { }; view! { - <> + - - {move || story.get().map(|story| match story { - None => view! {
"Error loading this story."
}, - Some(story) => view! { -
-
- -

{story.title}

-
- - "("{story.domain}")" - - {story.user.map(|user| view! {

- {story.points} - " points | by " - {user.clone()} - {format!(" {}", story.time_ago)} -

})} -
-
-

- {if story.comments_count.unwrap_or_default() > 0 { - format!("{} comments", story.comments_count.unwrap_or_default()) - } else { - "No comments yet.".into() - }} -

-
    - } - /> -
-
+ {move || story.get().map(|story| match story { + None => view! {
"Error loading this story."
}, + Some(story) => view! { +
+
+ +

{story.title}

+
+ + "("{story.domain}")" + + {story.user.map(|user| view! {

+ {story.points} + " points | by " + {user.clone()} + {format!(" {}", story.time_ago)} +

})}
- }}) - } - - +
+

+ {if story.comments_count.unwrap_or_default() > 0 { + format!("{} comments", story.comments_count.unwrap_or_default()) + } else { + "No comments yet.".into() + }} +

+
    + } + /> +
+
+
+ }})} + } } diff --git a/examples/hackernews_axum/src/routes/stories.rs b/examples/hackernews_axum/src/routes/stories.rs index d9f0409f0..09ba7ed11 100644 --- a/examples/hackernews_axum/src/routes/stories.rs +++ b/examples/hackernews_axum/src/routes/stories.rs @@ -36,12 +36,11 @@ pub fn Stories() -> impl IntoView { let (pending, set_pending) = create_signal(false); let hide_more_link = move || { - pending() - || stories.get().unwrap_or(None).unwrap_or_default().len() < 28 + stories.get().unwrap_or(None).unwrap_or_default().len() < 28 + || pending() }; view! { -
@@ -65,20 +64,16 @@ pub fn Stories() -> impl IntoView { }} "page " {page} - "Loading..."

} + - - - "more >" - - -
+ "more >" + +
diff --git a/examples/hackernews_axum/src/routes/story.rs b/examples/hackernews_axum/src/routes/story.rs index 8e0b3e84e..edeaa9073 100644 --- a/examples/hackernews_axum/src/routes/story.rs +++ b/examples/hackernews_axum/src/routes/story.rs @@ -25,48 +25,45 @@ pub fn Story() -> impl IntoView { }; view! { - <> + - - {move || story.get().map(|story| match story { - None => view! {
"Error loading this story."
}, - Some(story) => view! { -
-
- -

{story.title}

-
- - "("{story.domain}")" - - {story.user.map(|user| view! {

- {story.points} - " points | by " - {user.clone()} - {format!(" {}", story.time_ago)} -

})} -
-
-

- {if story.comments_count.unwrap_or_default() > 0 { - format!("{} comments", story.comments_count.unwrap_or_default()) - } else { - "No comments yet.".into() - }} -

-
    - } - /> -
-
+ {move || story.get().map(|story| match story { + None => view! {
"Error loading this story."
}, + Some(story) => view! { +
+
+ +

{story.title}

+
+ + "("{story.domain}")" + + {story.user.map(|user| view! {

+ {story.points} + " points | by " + {user.clone()} + {format!(" {}", story.time_ago)} +

})}
- }}) - } - - +
+

+ {if story.comments_count.unwrap_or_default() > 0 { + format!("{} comments", story.comments_count.unwrap_or_default()) + } else { + "No comments yet.".into() + }} +

+
    + } + /> +
+
+
+ }})} + } }