summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Reeder <colin@vpzom.click>2020-07-22 22:36:46 -0600
committerColin Reeder <colin@vpzom.click>2020-07-22 22:36:46 -0600
commit47838d5381cf79e15889240f0f02ec246a1a4a86 (patch)
tree5723ab9c97ff64fb1a852c67dc372675bbea1d78
parentc7e0570da3b3ebc163feb9aab942d52996d3ae27 (diff)
Link to comment parent & post (#70)
-rw-r--r--res/lang/en.ftl2
-rw-r--r--res/lang/eo.ftl2
-rw-r--r--src/components/mod.rs15
-rw-r--r--src/resp_types.rs21
-rw-r--r--src/routes/mod.rs44
5 files changed, 70 insertions, 14 deletions
diff --git a/res/lang/en.ftl b/res/lang/en.ftl
index 2fe6728..018bd77 100644
--- a/res/lang/en.ftl
+++ b/res/lang/en.ftl
@@ -95,6 +95,8 @@ timeago_now = now
timeago_future = in the future
title = Title
to = to
+to_parent = View Parent
+to_post = Comment on
url = URL
user_edit_description_prompt = Profile Description:
user_edit_not_you = You can only edit your own profile.
diff --git a/res/lang/eo.ftl b/res/lang/eo.ftl
index 5b1fa51..1ff0292 100644
--- a/res/lang/eo.ftl
+++ b/res/lang/eo.ftl
@@ -95,6 +95,8 @@ timeago_now = nune
timeago_future = estontece
title = Titolo
to = al
+to_parent = Vidi gepatron
+to_post = Komento sur
url = URL
user_edit_description_prompt = Priskribo de Profilo
user_edit_not_you = Vi nur rajtas redakti vian propran profilon.
diff --git a/src/components/mod.rs b/src/components/mod.rs
index 4b5faf9..e3cd604 100644
--- a/src/components/mod.rs
+++ b/src/components/mod.rs
@@ -4,9 +4,9 @@ use std::borrow::{Borrow, Cow};
use std::collections::HashMap;
use crate::resp_types::{
- RespMinimalAuthorInfo, RespMinimalCommentInfo, RespMinimalCommunityInfo, RespNotification,
- RespNotificationInfo, RespPostCommentInfo, RespPostInfo, RespPostListPost, RespThingComment,
- RespThingInfo,
+ RespCommentInfo, RespMinimalAuthorInfo, RespMinimalCommentInfo, RespMinimalCommunityInfo,
+ RespNotification, RespNotificationInfo, RespPostCommentInfo, RespPostInfo, RespPostListPost,
+ RespThingComment, RespThingInfo,
};
use crate::util::{abbreviate_link, author_is_me};
use crate::PageBaseData;
@@ -151,6 +151,15 @@ impl<'a> HavingContent for RespPostCommentInfo<'a> {
}
}
+impl<'a> HavingContent for RespCommentInfo<'a> {
+ fn content_text(&self) -> Option<&str> {
+ self.base.content_text()
+ }
+ fn content_html(&self) -> Option<&str> {
+ self.base.content_html()
+ }
+}
+
impl<'a> HavingContent for RespPostInfo<'a> {
fn content_text(&self) -> Option<&str> {
self.content_text.as_deref()
diff --git a/src/resp_types.rs b/src/resp_types.rs
index 77bce6c..e7a18f1 100644
--- a/src/resp_types.rs
+++ b/src/resp_types.rs
@@ -88,6 +88,22 @@ impl<'a> AsRef<RespMinimalCommentInfo<'a>> for RespPostCommentInfo<'a> {
}
#[derive(Deserialize, Debug)]
+pub struct RespCommentInfo<'a> {
+ #[serde(flatten)]
+ pub base: RespPostCommentInfo<'a>,
+
+ pub parent: Option<JustID>,
+ #[serde(borrow)]
+ pub post: Option<RespMinimalPostInfo<'a>>,
+}
+
+impl<'a> AsRef<RespPostCommentInfo<'a>> for RespCommentInfo<'a> {
+ fn as_ref(&self) -> &RespPostCommentInfo<'a> {
+ &self.base
+ }
+}
+
+#[derive(Deserialize, Debug)]
pub struct RespPostInfo<'a> {
#[serde(flatten, borrow)]
pub base: RespPostListPost<'a>,
@@ -143,6 +159,11 @@ pub struct RespLoginInfo {
pub struct Empty {}
#[derive(Deserialize, Debug)]
+pub struct JustID {
+ pub id: i64,
+}
+
+#[derive(Deserialize, Debug)]
pub struct RespYourFollow {
pub accepted: bool,
}
diff --git a/src/routes/mod.rs b/src/routes/mod.rs
index 779740e..4ebe357 100644
--- a/src/routes/mod.rs
+++ b/src/routes/mod.rs
@@ -7,8 +7,8 @@ use crate::components::{
ThingItem, UserLink,
};
use crate::resp_types::{
- RespInstanceInfo, RespNotification, RespPostCommentInfo, RespPostListPost, RespThingInfo,
- RespUserInfo,
+ RespCommentInfo, RespInstanceInfo, RespNotification, RespPostCommentInfo, RespPostListPost,
+ RespThingInfo, RespUserInfo,
};
use crate::util::author_is_me;
use crate::PageBaseData;
@@ -213,14 +213,36 @@ async fn page_comment_inner(
)
.await?;
let api_res = hyper::body::to_bytes(api_res.into_body()).await?;
- let comment: RespPostCommentInfo<'_> = serde_json::from_slice(&api_res)?;
+ let comment: RespCommentInfo<'_> = serde_json::from_slice(&api_res)?;
let title = lang.tr("comment", None);
Ok(html_response(render::html! {
<HTPage base_data={&base_data} lang={&lang} title={&title}>
+ {
+ if let Some(post) = &comment.post {
+ Some(render::rsx! {
+ <p>
+ {lang.tr("to_post", None)}{" "}<a href={format!("/posts/{}", post.id)}>{post.title.as_ref()}</a>
+ </p>
+ })
+ } else {
+ None
+ }
+ }
<p>
- <small><cite><UserLink user={comment.author.as_ref()} /></cite>{":"}</small>
+ {
+ if let Some(parent) = &comment.parent {
+ Some(render::rsx! {
+ <div>
+ <small><a href={format!("/comments/{}", parent.id)}>{"<- "}{lang.tr("to_parent", None)}</a></small>
+ </div>
+ })
+ } else {
+ None
+ }
+ }
+ <small><cite><UserLink user={comment.as_ref().author.as_ref()} /></cite>{":"}</small>
<Content src={&comment} />
</p>
<div class={"actionList"}>
@@ -229,15 +251,15 @@ async fn page_comment_inner(
Some(render::rsx! {
<>
{
- if comment.your_vote.is_some() {
+ if comment.as_ref().your_vote.is_some() {
render::rsx! {
- <form method={"POST"} action={format!("/comments/{}/unlike", comment.as_ref().id)}>
+ <form method={"POST"} action={format!("/comments/{}/unlike", comment.as_ref().as_ref().id)}>
<button type={"submit"}>{lang.tr("like_undo", None)}</button>
</form>
}
} else {
render::rsx! {
- <form method={"POST"} action={format!("/comments/{}/like", comment.as_ref().id)}>
+ <form method={"POST"} action={format!("/comments/{}/like", comment.as_ref().as_ref().id)}>
<button type={"submit"}>{lang.tr("like", None)}</button>
</form>
}
@@ -250,9 +272,9 @@ async fn page_comment_inner(
}
}
{
- if author_is_me(&comment.author, &base_data.login) {
+ if author_is_me(&comment.as_ref().author, &base_data.login) {
Some(render::rsx! {
- <a href={format!("/comments/{}/delete", comment.as_ref().id)}>{lang.tr("delete", None)}</a>
+ <a href={format!("/comments/{}/delete", comment.as_ref().as_ref().id)}>{lang.tr("delete", None)}</a>
})
} else {
None
@@ -269,7 +291,7 @@ async fn page_comment_inner(
{
if base_data.login.is_some() {
Some(render::rsx! {
- <form method={"POST"} action={format!("/comments/{}/submit_reply", comment.as_ref().id)}>
+ <form method={"POST"} action={format!("/comments/{}/submit_reply", comment.as_ref().as_ref().id)}>
<div>
<MaybeFillTextArea values={&prev_values} name={"content_markdown"} default_value={None} />
</div>
@@ -282,7 +304,7 @@ async fn page_comment_inner(
}
<ul>
{
- comment.replies.as_ref().unwrap().iter().map(|reply| {
+ comment.as_ref().replies.as_ref().unwrap().iter().map(|reply| {
render::rsx! {
<Comment comment={reply} base_data={&base_data} lang={&lang} />
}