Make it possible to respond to a comment
This commit is contained in:
parent
56f4a598e2
commit
b506e93bd8
@ -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<i32>
|
||||
struct CommentQuery {
|
||||
responding_to: Option<i32>
|
||||
}
|
||||
|
||||
#[post("/~/<blog>/<slug>/comment", data = "<data>")]
|
||||
fn create(blog: String, slug: String, data: Form<NewCommentForm>, user: User, conn: DbConn) -> Redirect {
|
||||
#[derive(FromForm)]
|
||||
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 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,
|
||||
|
@ -9,11 +9,6 @@ Comment "{{ post.title }}"
|
||||
<form method="post">
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content"></textarea>
|
||||
|
||||
{% if responding_to %}
|
||||
<input name="respond_to" value="{{ responding_to }}">
|
||||
{% endif %}
|
||||
|
||||
<input type="submit" value="Submit comment"/>
|
||||
</form>
|
||||
{% endblock content %}
|
||||
|
@ -18,7 +18,8 @@
|
||||
<div id="comment-{{ comment.id }}">
|
||||
<b>{{ comment.author.display_name }}</b>
|
||||
<div>{{ comment.content | safe }}</div>
|
||||
<a href="comment?responding_to={{ comment.id }}">Respond</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<a href="comment">Comment</a>
|
||||
<a href="comment?">Comment</a>
|
||||
{% endblock content %}
|
||||
|
Loading…
Reference in New Issue
Block a user