Skip to content

Commit

Permalink
Add topic review (fixes #52) (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Nov 9, 2022
1 parent a07abab commit ef3830c
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 135 deletions.
6 changes: 6 additions & 0 deletions src/api/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub async fn get_post(id: i32, auth: Option<Sensitive<String>>) -> Result<GetPos
};
let mut post: GetPostResponse = get("/post", &params).await?;

// simply ignore deleted/removed comments
post.comments = post
.comments
.into_iter()
.filter(|c| !c.comment.deleted && !c.comment.removed)
.collect();
// show oldest comments first
post.comments.sort_unstable_by_key(|a| a.comment.published);

Expand Down
15 changes: 13 additions & 2 deletions src/routes/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
post::get_post,
},
error::ErrorPage,
pagination::PAGE_ITEMS,
rocket_uri_macro_login,
routes::post::rocket_uri_macro_view_topic,
site_fairing::SiteData,
Expand Down Expand Up @@ -49,7 +50,7 @@ async fn render_editor(
reply: Option<i32>,
site_data: SiteData,
) -> Result<Template, ErrorPage> {
let post = get_post(post_id, site_data.auth.clone()).await?;
let mut post = get_post(post_id, site_data.auth.clone()).await?;
let mut editor_action = format!("/comment?t={}", post.post_view.post.id.0);
if let Some(edit_comment_id) = edit_comment_id {
editor_action = format!("{}&edit={}", editor_action, edit_comment_id);
Expand All @@ -58,9 +59,19 @@ async fn render_editor(
editor_action = format!("{}&reply={}", editor_action, reply);
}
let message = message.unwrap_or_default();

// for topic review
let all_comments = post.comments.clone();
post.comments = post
.comments
.into_iter()
.rev()
.take(PAGE_ITEMS as usize)
.collect();

Ok(Template::render(
"comment_editor",
context!(site_data, post, message, editor_action),
context!(site_data, post, message, editor_action, all_comments),
))
}

Expand Down
7 changes: 0 additions & 7 deletions src/routes/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ pub async fn view_topic(
) -> Result<Template, ErrorPage> {
let mut post = get_post(t, site_data.auth.clone()).await?;

// simply ignore deleted/removed comments
post.comments = post
.comments
.into_iter()
.filter(|c| !c.comment.deleted && !c.comment.removed)
.collect();
post.comments.sort_by_key(|c| c.comment.published);
let all_comments = post.comments.clone();
post.comments = post
.comments
Expand Down
15 changes: 15 additions & 0 deletions templates/comment_editor.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@

{{> components/editor_form editor_title=(i18n site_data "post_reply")}}

<h3 id="review" class="review">
<span class="right-box"><a href="#review" onclick="viewableArea(getElementById('topicreview'), true); var rev_text = getElementById('review').getElementsByTagName('a').item(0).firstChild; if (rev_text.data == 'Expand\u0020view'){rev_text.data = 'Collapse\u0020view'; } else if (rev_text.data == 'Collapse\u0020view'){rev_text.data = 'Expand\u0020view'};">{{{i18n site_data "expand_view"}}}</a></span>
{{{i18n site_data "topic_review_title" post.post_view.post.name }}}
</h3>

<div id="topicreview" class="topicreview">
{{#each post.comments}}
{{> components/comment site_data=../site_data hide_author=true }}
{{/each}}
{{log (len post.comments)}}
{{#unless eq (len post.comments) 20}}
{{> components/post hide_author=true }}
{{/unless}}
</div>

{{> components/footer }}
62 changes: 62 additions & 0 deletions templates/components/comment.html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<div id="p{{this.comment.id}}" class="post has-profile bg{{add (mod @index 2) 1}}">
<div class="inner">

{{#unless hide_author }}
{{> components/post_profile user=this.creator site_data=../site_data }}
{{/unless}}

<div class="postbody">
<h3>
<a href="/view_topic?p={{this.post.id}}#p1">{{this.post.name}}</a>
</h3>
{{#if ../site_data.site.my_user.local_user_view.person.id}}
<ul class="post-buttons">
{{#if (eq this.creator.id ../site_data.site.my_user.local_user_view.person.id)}}
<li>
<a href="/comment_editor?t={{this.post.id}}&edit={{this.comment.id}}" class="button button-icon-only">
<i class="icon fa-pencil fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n ../site_data "action_edit"}}}</span>
</a>
</li>
{{/if}}
<li>
<a href="/report?reply={{this.comment.id}}" class="button button-icon-only">
<i class="icon fa-exclamation fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n ../site_data "action_report"}}}</span>
</a>
</li>
<li>
<a href="comment_editor?t={{this.post.id}}&reply={{this.comment.id}}" class="button button-icon-only">
<i class="icon fa-reply fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n ../site_data "action_reply"}}}</span>
</a>
</li>
</ul>
{{/if}}
<p class="author">
<a class="unread" href="/view_topic?t={{this.post.id}}{{#if ../pagination}}&page={{../pagination.current_page}}{{/if}}#p{{this.comment.id}}">
<i class="icon fa-file fa-fw icon-lightgray icon-md" aria-hidden="true"></i><span class="sr-only">Post</span>
</a>
<span class="responsive-hide">by <strong><a href="/view_profile?u={{this.creator.id}}" class="username">{{{user_actor_id this.creator}}}</a></strong> &raquo; </span>
<time datetime="{{timestamp_machine this.comment.published}}">{{timestamp_human this.comment.published}}</time>
<a href="{{this.comment.ap_id}}"><img src="/assets/images/icons/fedilink.svg" width="16px" height="16px"></a>
{{#if this.comment.parent_id}}
<span style="float: right; margin-right: 100px">
{{{i18n ../site_data "responding_to"}}} <a href="/view_topic?t={{this.post.id}}&page={{comment_page this.comment.parent_id ../all_comments}}#p{{this.comment.parent_id}}">#{{this.comment.parent_id}}</a>
</span>
{{/if}}
</p>
<div class="content">{{{markdown this.comment.content}}}</div>
</div>
{{#if this.creator.bio}}
<div class="signature">
{{{markdown this.creator.bio}}}
</div>
{{/if}}

<div class="back2top">
<a href="#top" class="top">
<i class="icon fa-chevron-circle-up fa-fw icon-gray" aria-hidden="true"></i>
<span class="sr-only">{{{i18n ../site_data "go_to_top"}}}</span>
</a>
</div>

</div>
</div>
68 changes: 68 additions & 0 deletions templates/components/post.html.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<div id="p1" class="post has-profile bg2">
<div class="inner">

{{#unless hide_author }}
{{> components/post_profile user=post.post_view.creator }}
{{/unless}}

<div class="postbody">
<div id="post_content1">

<h3 class="first">
<a href="/view_topic?p={{post.post_view.post.id}}#p1">{{post.post_view.post.name}}</a>
</h3>
{{#if site_data.site.my_user.local_user_view.person.id}}
<ul class="post-buttons">
{{#if (eq post.post_view.creator.id site_data.site.my_user.local_user_view.person.id)}}
<li>
<a href="/post_editor?f={{post.post_view.community.id}}&edit={{post.post_view.post.id}}" class="button button-icon-only">
<i class="icon fa-pencil fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n site_data "action_edit"}}}</span>
</a>
</li>
{{/if}}
<li>
<a href="/report?thread={{post.post_view.post.id}}" class="button button-icon-only">
<i class="icon fa-exclamation fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n site_data "action_report"}}}</span>
</a>
</li>
</ul>
{{/if}}
<p class="author">
<a class="unread" href="/view_topic?t={{post.post_view.post.id}}#p1">
<i class="icon fa-file fa-fw icon-lightgray icon-md" aria-hidden="true"></i><span class="sr-only">Post</span>
</a>
<span class="responsive-hide">by <strong><a href="/view_profile?u={{post.post_view.creator.id}}" class="username">{{{user_actor_id post.post_view.creator}}}</a></strong> &raquo; </span>
<time datetime="{{timestamp_machine post.post_view.post.published}}">{{timestamp_human post.post_view.post.published}}</time>
<a href="{{post.post_view.post.ap_id}}"><img src="/assets/images/icons/fedilink.svg" width="16px" height="16px"></a>
</p>
<div class="content">
{{#if post.post_view.post.url}}
{{#if is_image_url}}
<img src="{{post.post_view.post.url}}" />
<br />
<br />
{{else}}
<a href="{{post.post_view.post.url}}">{{post.post_view.post.url}}</a>
<br />
<br />
{{/if}}
{{/if}}
{{{markdown post.post_view.post.body}}}
</div>
{{#if post.post_view.creator.bio}}
<div class="signature">
{{{markdown post.post_view.creator.bio}}}
</div>
{{/if}}
</div>
</div>

<div class="back2top">
<a href="#top" class="top">
<i class="icon fa-chevron-circle-up fa-fw icon-gray" aria-hidden="true"></i>
<span class="sr-only">{{{i18n site_data "go_to_top"}}}</span>
</a>
</div>

</div>
</div>
128 changes: 2 additions & 126 deletions templates/view_topic.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,135 +17,11 @@
</div>

{{#if (eq pagination.current_page 1)}}
<div id="p1" class="post has-profile bg2">
<div class="inner">

{{> components/post_profile user=post.post_view.creator }}

<div class="postbody">
<div id="post_content1">

<h3 class="first">
<a href="/view_topic?p={{post.post_view.post.id}}#p1">{{post.post_view.post.name}}</a>
</h3>
{{#if site_data.site.my_user.local_user_view.person.id}}
<ul class="post-buttons">
{{#if (eq post.post_view.creator.id site_data.site.my_user.local_user_view.person.id)}}
<li>
<a href="/post_editor?f={{post.post_view.community.id}}&edit={{post.post_view.post.id}}" class="button button-icon-only">
<i class="icon fa-pencil fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n site_data "action_edit"}}}</span>
</a>
</li>
{{/if}}
<li>
<a href="/report?thread={{post.post_view.post.id}}" class="button button-icon-only">
<i class="icon fa-exclamation fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n site_data "action_report"}}}</span>
</a>
</li>
</ul>
{{/if}}
<p class="author">
<a class="unread" href="/view_topic?t={{post.post_view.post.id}}#p1">
<i class="icon fa-file fa-fw icon-lightgray icon-md" aria-hidden="true"></i><span class="sr-only">Post</span>
</a>
<span class="responsive-hide">by <strong><a href="/view_profile?u={{post.post_view.creator.id}}" class="username">{{{user_actor_id post.post_view.creator}}}</a></strong> &raquo; </span>
<time datetime="{{timestamp_machine post.post_view.post.published}}">{{timestamp_human post.post_view.post.published}}</time>
<a href="{{post.post_view.post.ap_id}}"><img src="/assets/images/icons/fedilink.svg" width="16px" height="16px"></a>
</p>
<div class="content">
{{#if post.post_view.post.url}}
{{#if is_image_url}}
<img src="{{post.post_view.post.url}}" />
<br />
<br />
{{else}}
<a href="{{post.post_view.post.url}}">{{post.post_view.post.url}}</a>
<br />
<br />
{{/if}}
{{/if}}
{{{markdown post.post_view.post.body}}}
</div>
{{#if post.post_view.creator.bio}}
<div class="signature">
{{{markdown post.post_view.creator.bio}}}
</div>
{{/if}}
</div>
</div>

<div class="back2top">
<a href="#top" class="top">
<i class="icon fa-chevron-circle-up fa-fw icon-gray" aria-hidden="true"></i>
<span class="sr-only">{{{i18n site_data "go_to_top"}}}</span>
</a>
</div>

</div>
</div>
{{> components/post }}
{{/if}}

{{#each post.comments}}
<div id="p{{this.comment.id}}" class="post has-profile bg{{add (mod @index 2) 1}}">
<div class="inner">

{{> components/post_profile user=this.creator site_data=../site_data }}

<div class="postbody">
<h3>
<a href="/view_topic?p={{this.post.id}}#p1">{{this.post.name}}</a>
</h3>
{{#if ../site_data.site.my_user.local_user_view.person.id}}
<ul class="post-buttons">
{{#if (eq this.creator.id ../site_data.site.my_user.local_user_view.person.id)}}
<li>
<a href="/comment_editor?t={{this.post.id}}&edit={{this.comment.id}}" class="button button-icon-only">
<i class="icon fa-pencil fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n ../site_data "action_edit"}}}</span>
</a>
</li>
{{/if}}
<li>
<a href="/report?reply={{this.comment.id}}" class="button button-icon-only">
<i class="icon fa-exclamation fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n ../site_data "action_report"}}}</span>
</a>
</li>
<li>
<a href="comment_editor?t={{this.post.id}}&reply={{this.comment.id}}" class="button button-icon-only">
<i class="icon fa-reply fa-fw" aria-hidden="true"></i><span class="sr-only">{{{i18n ../site_data "action_reply"}}}</span>
</a>
</li>
</ul>
{{/if}}
<p class="author">
<a class="unread" href="/view_topic?t={{this.post.id}}&page={{../pagination.current_page}}#p{{this.comment.id}}">
<i class="icon fa-file fa-fw icon-lightgray icon-md" aria-hidden="true"></i><span class="sr-only">Post</span>
</a>
<span class="responsive-hide">by <strong><a href="/view_profile?u={{this.creator.id}}" class="username">{{{user_actor_id this.creator}}}</a></strong> &raquo; </span>
<time datetime="{{timestamp_machine this.comment.published}}">{{timestamp_human this.comment.published}}</time>
<a href="{{this.comment.ap_id}}"><img src="/assets/images/icons/fedilink.svg" width="16px" height="16px"></a>
{{#if this.comment.parent_id}}
<span style="float: right; margin-right: 100px">
{{{i18n ../site_data "responding_to"}}} <a href="/view_topic?t={{this.post.id}}&page={{comment_page this.comment.parent_id ../all_comments}}#p{{this.comment.parent_id}}">#{{this.comment.parent_id}}</a>
</span>
{{/if}}
</p>
<div class="content">{{{markdown this.comment.content}}}</div>
</div>
{{#if this.creator.bio}}
<div class="signature">
{{{markdown this.creator.bio}}}
</div>
{{/if}}

<div class="back2top">
<a href="#top" class="top">
<i class="icon fa-chevron-circle-up fa-fw icon-gray" aria-hidden="true"></i>
<span class="sr-only">{{{i18n ../site_data "go_to_top"}}}</span>
</a>
</div>

</div>
</div>
{{> components/comment }}
{{/each}}

<div class="action-bar bar-bottom">
Expand Down

0 comments on commit ef3830c

Please sign in to comment.