~vpzom/hitide

47838d5381cf79e15889240f0f02ec246a1a4a86 — Colin Reeder 9 months ago c7e0570
Link to comment parent & post (#70)
5 files changed, 70 insertions(+), 14 deletions(-)

M res/lang/en.ftl
M res/lang/eo.ftl
M src/components/mod.rs
M src/resp_types.rs
M src/routes/mod.rs
M res/lang/en.ftl => res/lang/en.ftl +2 -0
@@ 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.

M res/lang/eo.ftl => res/lang/eo.ftl +2 -0
@@ 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.

M src/components/mod.rs => src/components/mod.rs +12 -3
@@ 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()

M src/resp_types.rs => src/resp_types.rs +21 -0
@@ 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,
}

M src/routes/mod.rs => src/routes/mod.rs +33 -11
@@ 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} />
                        }