diff options
author | Colin Reeder <colin@vpzom.click> | 2020-11-11 22:42:08 -0700 |
---|---|---|
committer | Colin Reeder <colin@vpzom.click> | 2020-11-11 22:43:48 -0700 |
commit | 19a16864e5a0a31de923d13050d4a5b43da69d45 (patch) | |
tree | 7bc13ca71a04626352b3231b855f062bfee69e05 | |
parent | 73d29fc3400c54f1a5d8cfe5d8a1ead7f2d60eda (diff) |
Show comment count in post lists
-rw-r--r-- | res/lang/en.ftl | 1 | ||||
-rw-r--r-- | res/lang/eo.ftl | 1 | ||||
-rw-r--r-- | src/components/mod.rs | 48 | ||||
-rw-r--r-- | src/resp_types.rs | 23 |
4 files changed, 46 insertions, 27 deletions
diff --git a/res/lang/en.ftl b/res/lang/en.ftl index b1892e1..33ecc3f 100644 --- a/res/lang/en.ftl +++ b/res/lang/en.ftl @@ -61,6 +61,7 @@ or_start = Or password_prompt = Password: post_approve = Approve post_approve_undo = Remove from Community +post_comments_count = { $count } comments post_delete_question = Delete this post? post_delete_title = Delete Post post_likes_nothing = Looks like nobody has liked this post yet. diff --git a/res/lang/eo.ftl b/res/lang/eo.ftl index 4f0ad33..03e5ba1 100644 --- a/res/lang/eo.ftl +++ b/res/lang/eo.ftl @@ -61,6 +61,7 @@ or_start = Aŭ password_prompt = Pasvorto: post_approve = Aprobi post_approve_undo = Forpreni el komunumo +post_comments_count = { $count } komentoj post_delete_question = Ĉu vi volas forigi ĉi tiun poŝton? post_delete_title = Forigi Poŝton post_likes_nothing = Ŝajnas, ke neniu ankoraŭ ŝatis ĉi tion poŝton. diff --git a/src/components/mod.rs b/src/components/mod.rs index f5bc16f..dc7442d 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -299,11 +299,11 @@ pub fn PostItem<'a>( ) { render::rsx! { <li> - <a href={format!("/posts/{}", post.as_ref().id)}> - {post.as_ref().title.as_ref()} + <a href={format!("/posts/{}", post.as_ref().as_ref().id)}> + {post.as_ref().as_ref().title.as_ref()} </a> { - if let Some(href) = &post.href { + if let Some(href) = &post.as_ref().href { Some(render::rsx! { <> {" "} @@ -315,27 +315,31 @@ pub fn PostItem<'a>( } } <br /> - {lang.tr("submitted", None)} - { - if no_user { - None - } else { - Some(render::rsx! { - <> - {" "}{lang.tr("by", None)}{" "}<UserLink user={post.author.as_ref()} /> - </> - }) + <small> + {lang.tr("submitted", None)} + { + if no_user { + None + } else { + Some(render::rsx! { + <> + {" "}{lang.tr("by", None)}{" "}<UserLink user={post.as_ref().author.as_ref()} /> + </> + }) + } } - } - { - if !in_community { - Some(render::rsx! { - <>{" "}{lang.tr("to", None)}{" "}<CommunityLink community={&post.community} /></> - }) - } else { - None + { + if !in_community { + Some(render::rsx! { + <>{" "}{lang.tr("to", None)}{" "}<CommunityLink community={&post.as_ref().community} /></> + }) + } else { + None + } } - } + {" | "} + {lang.tr("post_comments_count", Some(&fluent::fluent_args!["count" => post.replies_count_total])).into_owned()} + </small> </li> } } diff --git a/src/resp_types.rs b/src/resp_types.rs index 0382cc9..e77d03d 100644 --- a/src/resp_types.rs +++ b/src/resp_types.rs @@ -17,7 +17,7 @@ pub struct RespMinimalPostInfo<'a> { } #[derive(Deserialize, Debug)] -pub struct RespPostListPost<'a> { +pub struct RespSomePostInfo<'a> { #[serde(flatten)] pub base: RespMinimalPostInfo<'a>, pub href: Option<Cow<'a, str>>, @@ -28,13 +28,26 @@ pub struct RespPostListPost<'a> { pub community: RespMinimalCommunityInfo<'a>, } -impl<'a> AsRef<RespMinimalPostInfo<'a>> for RespPostListPost<'a> { +impl<'a> AsRef<RespMinimalPostInfo<'a>> for RespSomePostInfo<'a> { fn as_ref(&self) -> &RespMinimalPostInfo<'a> { &self.base } } #[derive(Deserialize, Debug)] +pub struct RespPostListPost<'a> { + #[serde(flatten, borrow)] + pub base: RespSomePostInfo<'a>, + pub replies_count_total: i64, +} + +impl<'a> AsRef<RespSomePostInfo<'a>> for RespPostListPost<'a> { + fn as_ref(&self) -> &RespSomePostInfo<'a> { + &self.base + } +} + +#[derive(Deserialize, Debug)] #[serde(tag = "type")] pub enum RespThingInfo<'a> { #[serde(rename = "post")] @@ -114,7 +127,7 @@ impl<'a> AsRef<RespPostCommentInfo<'a>> for RespCommentInfo<'a> { #[derive(Deserialize, Debug)] pub struct RespPostInfo<'a> { #[serde(flatten, borrow)] - pub base: RespPostListPost<'a>, + pub base: RespSomePostInfo<'a>, pub content_text: Option<Cow<'a, str>>, pub content_html: Option<Cow<'a, str>>, @@ -126,8 +139,8 @@ pub struct RespPostInfo<'a> { pub your_vote: Option<Empty>, } -impl<'a> AsRef<RespPostListPost<'a>> for RespPostInfo<'a> { - fn as_ref(&self) -> &RespPostListPost<'a> { +impl<'a> AsRef<RespSomePostInfo<'a>> for RespPostInfo<'a> { + fn as_ref(&self) -> &RespSomePostInfo<'a> { &self.base } } |