Actually redirect when writing a new comment

This commit is contained in:
Bat 2018-05-10 14:58:17 +01:00
parent 80964b1857
commit 56f4a598e2
3 changed files with 7 additions and 6 deletions

View File

@ -21,11 +21,11 @@ struct NewCommentForm {
pub respond_to: Option<i32> pub respond_to: Option<i32>
} }
#[post("/~/<_blog>/<slug>/comment", data = "<data>")] #[post("/~/<blog>/<slug>/comment", data = "<data>")]
fn create(_blog: String, slug: String, data: Form<NewCommentForm>, user: User, conn: DbConn) -> Redirect { fn create(blog: String, slug: String, data: Form<NewCommentForm>, user: User, conn: DbConn) -> Redirect {
let post = Post::find_by_slug(&*conn, slug).unwrap(); let post = Post::find_by_slug(&*conn, slug.clone()).unwrap();
let form = data.get(); let form = data.get();
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: form.respond_to,
post_id: post.id, post_id: post.id,
@ -34,5 +34,5 @@ fn create(_blog: String, slug: String, data: Form<NewCommentForm>, user: User, c
sensitive: false, sensitive: false,
spoiler_text: "".to_string() spoiler_text: "".to_string()
}); });
Redirect::to("") Redirect::to(format!("/~/{}/{}/#comment-{}", blog, slug, comment.id).as_ref())
} }

View File

@ -27,6 +27,7 @@ fn details(blog: String, slug: String, conn: DbConn) -> Template {
"blog": blog, "blog": blog,
"comments": comments.into_iter().map(|c| { "comments": comments.into_iter().map(|c| {
json!({ json!({
"id": c.id,
"content": c.content, "content": c.content,
"author": c.get_author(&*conn) "author": c.get_author(&*conn)
}) })

View File

@ -15,7 +15,7 @@
<hr> <hr>
<h2>Comments</h2> <h2>Comments</h2>
{% for comment in comments %} {% for comment in comments %}
<div> <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>
</div> </div>