refactor(templates/render): Add generic post editing template
Adds a generic template that can be used for submitting, responding to and editing posts.
This commit is contained in:
parent
4c0e6552e8
commit
ec712cc4c0
6 changed files with 156 additions and 72 deletions
|
|
@ -99,7 +99,7 @@ fn anonymous() -> Author {
|
|||
#[derive(Deserialize)]
|
||||
pub struct NewThreadForm {
|
||||
pub title: String,
|
||||
pub body: String,
|
||||
pub post: String,
|
||||
}
|
||||
|
||||
const NEW_THREAD_LENGTH_ERR: &'static str = "Title and body can not be empty!";
|
||||
|
|
@ -112,16 +112,16 @@ pub fn submit_thread(state: State<AppState>,
|
|||
// Trim whitespace out of inputs:
|
||||
let input = NewThreadForm {
|
||||
title: input.title.trim().into(),
|
||||
body: input.body.trim().into(),
|
||||
post: input.post.trim().into(),
|
||||
};
|
||||
|
||||
// Perform simple validation and abort here if it fails:
|
||||
if input.title.is_empty() || input.body.is_empty() {
|
||||
if input.title.is_empty() || input.post.is_empty() {
|
||||
return state.renderer
|
||||
.send(NewThreadPage {
|
||||
alerts: vec![NEW_THREAD_LENGTH_ERR],
|
||||
title: Some(input.title),
|
||||
body: Some(input.body),
|
||||
post: Some(input.post),
|
||||
})
|
||||
.flatten()
|
||||
.map(|res| HttpResponse::Ok().content_type(HTML).body(res))
|
||||
|
|
@ -140,7 +140,7 @@ pub fn submit_thread(state: State<AppState>,
|
|||
|
||||
let msg = CreateThread {
|
||||
new_thread,
|
||||
body: input.body,
|
||||
post: input.post,
|
||||
};
|
||||
|
||||
state.db.send(msg)
|
||||
|
|
@ -158,7 +158,7 @@ pub fn submit_thread(state: State<AppState>,
|
|||
#[derive(Deserialize)]
|
||||
pub struct NewPostForm {
|
||||
pub thread_id: i32,
|
||||
pub body: String,
|
||||
pub post: String,
|
||||
}
|
||||
|
||||
/// This handler receives a "Reply"-form and redirects the user to the
|
||||
|
|
@ -172,7 +172,7 @@ pub fn reply_thread(state: State<AppState>,
|
|||
|
||||
let new_post = NewPost {
|
||||
thread_id: input.thread_id,
|
||||
body: input.body.trim().into(),
|
||||
body: input.post.trim().into(),
|
||||
author_name: author.name,
|
||||
author_email: author.email,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue