From 56f4a598e2a111aebfc570fff95f03494959ab4e Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 10 May 2018 14:58:17 +0100 Subject: [PATCH] Actually redirect when writing a new comment --- src/routes/comments.rs | 10 +++++----- src/routes/posts.rs | 1 + templates/posts/details.tera | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/routes/comments.rs b/src/routes/comments.rs index fab683c..4e95664 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -21,11 +21,11 @@ struct NewCommentForm { pub respond_to: Option } -#[post("/~/<_blog>//comment", data = "")] -fn create(_blog: String, slug: String, data: Form, user: User, conn: DbConn) -> Redirect { - let post = Post::find_by_slug(&*conn, slug).unwrap(); +#[post("/~///comment", data = "")] +fn create(blog: String, slug: String, data: Form, user: User, conn: DbConn) -> Redirect { + let post = Post::find_by_slug(&*conn, slug.clone()).unwrap(); let form = data.get(); - Comment::insert(&*conn, NewComment { + let comment = Comment::insert(&*conn, NewComment { content: form.content.clone(), in_response_to_id: form.respond_to, post_id: post.id, @@ -34,5 +34,5 @@ fn create(_blog: String, slug: String, data: Form, user: User, c sensitive: false, spoiler_text: "".to_string() }); - Redirect::to("") + Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id).as_ref()) } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index e039e04..dd9f2b7 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -27,6 +27,7 @@ fn details(blog: String, slug: String, conn: DbConn) -> Template { "blog": blog, "comments": comments.into_iter().map(|c| { json!({ + "id": c.id, "content": c.content, "author": c.get_author(&*conn) }) diff --git a/templates/posts/details.tera b/templates/posts/details.tera index 71cc171..ea7570e 100644 --- a/templates/posts/details.tera +++ b/templates/posts/details.tera @@ -15,7 +15,7 @@

Comments

{% for comment in comments %} -
+
{{ comment.author.display_name }}
{{ comment.content | safe }}