diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/mod.rs | 48 | ||||
-rw-r--r-- | src/resp_types.rs | 23 |
2 files changed, 44 insertions, 27 deletions
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 } } |