Make it possible to respond to a comment

This commit is contained in:
Bat 2018-05-10 15:26:12 +01:00
parent 56f4a598e2
commit b506e93bd8
3 changed files with 13 additions and 13 deletions

View File

@ -11,23 +11,27 @@ use models::users::User;
fn new(_blog: String, slug: String, _user: User, conn: DbConn) -> Template { fn new(_blog: String, slug: String, _user: User, conn: DbConn) -> Template {
let post = Post::find_by_slug(&*conn, slug).unwrap(); let post = Post::find_by_slug(&*conn, slug).unwrap();
Template::render("comments/new", json!({ Template::render("comments/new", json!({
"post": post "post": post,
})) }))
} }
#[derive(FromForm)] #[derive(FromForm)]
struct NewCommentForm { struct CommentQuery {
pub content: String, responding_to: Option<i32>
pub respond_to: Option<i32>
} }
#[post("/~/<blog>/<slug>/comment", data = "<data>")] #[derive(FromForm)]
fn create(blog: String, slug: String, data: Form<NewCommentForm>, user: User, conn: DbConn) -> Redirect { struct NewCommentForm {
pub content: String
}
#[post("/~/<blog>/<slug>/comment?<query>", data = "<data>")]
fn create(blog: String, slug: String, query: CommentQuery, data: Form<NewCommentForm>, user: User, conn: DbConn) -> Redirect {
let post = Post::find_by_slug(&*conn, slug.clone()).unwrap(); let post = Post::find_by_slug(&*conn, slug.clone()).unwrap();
let form = data.get(); let form = data.get();
let comment = Comment::insert(&*conn, NewComment { let comment = Comment::insert(&*conn, NewComment {
content: form.content.clone(), content: form.content.clone(),
in_response_to_id: form.respond_to, in_response_to_id: query.responding_to,
post_id: post.id, post_id: post.id,
author_id: user.id, author_id: user.id,
ap_url: None, ap_url: None,

View File

@ -9,11 +9,6 @@ Comment "{{ post.title }}"
<form method="post"> <form method="post">
<label for="content">Content</label> <label for="content">Content</label>
<textarea name="content"></textarea> <textarea name="content"></textarea>
{% if responding_to %}
<input name="respond_to" value="{{ responding_to }}">
{% endif %}
<input type="submit" value="Submit comment"/> <input type="submit" value="Submit comment"/>
</form> </form>
{% endblock content %} {% endblock content %}

View File

@ -18,7 +18,8 @@
<div id="comment-{{ comment.id }}"> <div id="comment-{{ comment.id }}">
<b>{{ comment.author.display_name }}</b> <b>{{ comment.author.display_name }}</b>
<div>{{ comment.content | safe }}</div> <div>{{ comment.content | safe }}</div>
<a href="comment?responding_to={{ comment.id }}">Respond</a>
</div> </div>
{% endfor %} {% endfor %}
<a href="comment">Comment</a> <a href="comment?">Comment</a>
{% endblock content %} {% endblock content %}