Form refill
This commit is contained in:
parent
9fd7514927
commit
34ae3d3ec4
2 changed files with 19 additions and 8 deletions
|
@ -18,7 +18,14 @@ pub async fn run_server(config: Arc<Config>, dbs: Dbs, templates: Arc<Templates>
|
||||||
let templates = templates.clone();
|
let templates = templates.clone();
|
||||||
let dbs = dbs.clone();
|
let dbs = dbs.clone();
|
||||||
move |req: tide::Request<()>| {
|
move |req: tide::Request<()>| {
|
||||||
serve_comments(req, config.clone(), templates.clone(), dbs.clone(), &[])
|
serve_comments(
|
||||||
|
req,
|
||||||
|
config.clone(),
|
||||||
|
templates.clone(),
|
||||||
|
dbs.clone(),
|
||||||
|
&[],
|
||||||
|
Context::new(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
app.at(&format!("{}t/:topic", config.root_url)).post({
|
app.at(&format!("{}t/:topic", config.root_url)).post({
|
||||||
|
@ -57,9 +64,8 @@ async fn serve_comments<'a>(
|
||||||
templates: Arc<Templates>,
|
templates: Arc<Templates>,
|
||||||
dbs: Dbs,
|
dbs: Dbs,
|
||||||
errors: &[String],
|
errors: &[String],
|
||||||
|
mut context: Context,
|
||||||
) -> tide::Result<tide::Response> {
|
) -> tide::Result<tide::Response> {
|
||||||
dbg!(req.peer_addr());
|
|
||||||
|
|
||||||
let Ok(topic) = req.param("topic") else {
|
let Ok(topic) = req.param("topic") else {
|
||||||
return Err(tide::Error::from_str(404, "No topic"))
|
return Err(tide::Error::from_str(404, "No topic"))
|
||||||
};
|
};
|
||||||
|
@ -70,7 +76,7 @@ async fn serve_comments<'a>(
|
||||||
|
|
||||||
let topic_hash = TopicHash::from_topic(topic);
|
let topic_hash = TopicHash::from_topic(topic);
|
||||||
|
|
||||||
let mut context = Context::new();
|
//let mut context = Context::new();
|
||||||
context.insert("config", &config);
|
context.insert("config", &config);
|
||||||
context.insert("admin", &admin);
|
context.insert("admin", &admin);
|
||||||
context.insert("new_comment_errors", errors);
|
context.insert("new_comment_errors", errors);
|
||||||
|
@ -214,6 +220,7 @@ async fn handle_post_comments(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut errors = Vec::new();
|
let mut errors = Vec::new();
|
||||||
|
let mut context = Context::new();
|
||||||
|
|
||||||
match req.body_form::<CommentQuery>().await? {
|
match req.body_form::<CommentQuery>().await? {
|
||||||
CommentQuery::NewComment(query) => {
|
CommentQuery::NewComment(query) => {
|
||||||
|
@ -281,11 +288,15 @@ async fn handle_post_comments(
|
||||||
.map_err(|e| error!("Adding pending comment: {:?}", e))
|
.map_err(|e| error!("Adding pending comment: {:?}", e))
|
||||||
.ok();
|
.ok();
|
||||||
notify_send.send(()).ok();
|
notify_send.send(()).ok();
|
||||||
|
} else {
|
||||||
|
context.insert("new_comment_author", &query.author);
|
||||||
|
context.insert("new_comment_email", &query.email);
|
||||||
|
context.insert("new_comment_text", &query.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
serve_comments(req, config, templates, dbs, &errors).await
|
serve_comments(req, config, templates, dbs, &errors, context).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_post_admin(
|
async fn handle_post_admin(
|
||||||
|
|
|
@ -47,11 +47,11 @@
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<label for="new_comment-author">Your name:</label>
|
<label for="new_comment-author">Your name:</label>
|
||||||
<input type="text" id="new_comment-author" name="author" required maxlenth="{{ config.comment_author_max_len }}"/><br/>
|
<input type="text" id="new_comment-author" name="author" maxlength="{{ config.comment_author_max_len }}"{% if new_comment_author %} value="{{ new_comment_author }}"{% endif %}/><br/>
|
||||||
<label for="new_comment-email">Your e-mail:</label>
|
<label for="new_comment-email">Your e-mail:</label>
|
||||||
<input type="email" id="new_comment-email" name="email" maxlength="{{ config.comment_email_max_len }}"/><br/>
|
<input type="email" id="new_comment-email" name="email" maxlength="{{ config.comment_email_max_len }}"{% if new_comment_email %} value="{{ new_comment_email }}"{% endif %}/><br/>
|
||||||
<label for="new_comment-text">Your comment:</label><br/>
|
<label for="new_comment-text">Your comment:</label><br/>
|
||||||
<textarea id="new_comment-text" name="text" maxlength="{{ config.comment_text_max_len }}"></textarea><br/>
|
<textarea id="new_comment-text" name="text" maxlength="{{ config.comment_text_max_len }}">{% if new_comment_text %}{{ new_comment_text }}{% endif %}</textarea><br/>
|
||||||
<button type="submit" name="a" value="new_comment">Post comment</button>
|
<button type="submit" name="a" value="new_comment">Post comment</button>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in a new issue