From b506e93bd82f7095a53b7198bfea0c9a207b64a9 Mon Sep 17 00:00:00 2001 From: Bat Date: Thu, 10 May 2018 15:26:12 +0100 Subject: [PATCH] Make it possible to respond to a comment --- src/routes/comments.rs | 18 +++++++++++------- templates/comments/new.tera | 5 ----- templates/posts/details.tera | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/routes/comments.rs b/src/routes/comments.rs index 4e95664..b51fb55 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -11,23 +11,27 @@ use models::users::User; fn new(_blog: String, slug: String, _user: User, conn: DbConn) -> Template { let post = Post::find_by_slug(&*conn, slug).unwrap(); Template::render("comments/new", json!({ - "post": post + "post": post, })) } #[derive(FromForm)] -struct NewCommentForm { - pub content: String, - pub respond_to: Option +struct CommentQuery { + responding_to: Option } -#[post("/~///comment", data = "")] -fn create(blog: String, slug: String, data: Form, user: User, conn: DbConn) -> Redirect { +#[derive(FromForm)] +struct NewCommentForm { + pub content: String +} + +#[post("/~///comment?", data = "")] +fn create(blog: String, slug: String, query: CommentQuery, data: Form, user: User, conn: DbConn) -> Redirect { let post = Post::find_by_slug(&*conn, slug.clone()).unwrap(); let form = data.get(); let comment = Comment::insert(&*conn, NewComment { content: form.content.clone(), - in_response_to_id: form.respond_to, + in_response_to_id: query.responding_to, post_id: post.id, author_id: user.id, ap_url: None, diff --git a/templates/comments/new.tera b/templates/comments/new.tera index 0536a43..2dc1448 100644 --- a/templates/comments/new.tera +++ b/templates/comments/new.tera @@ -9,11 +9,6 @@ Comment "{{ post.title }}"
- - {% if responding_to %} - - {% endif %} -
{% endblock content %} diff --git a/templates/posts/details.tera b/templates/posts/details.tera index ea7570e..0c62d14 100644 --- a/templates/posts/details.tera +++ b/templates/posts/details.tera @@ -18,7 +18,8 @@
{{ comment.author.display_name }}
{{ comment.content | safe }}
+ Respond
{% endfor %} - Comment + Comment {% endblock content %}