diff --git a/src/server.rs b/src/server.rs index 6177aa3..189bb62 100644 --- a/src/server.rs +++ b/src/server.rs @@ -18,7 +18,14 @@ pub async fn run_server(config: Arc, dbs: Dbs, templates: Arc let templates = templates.clone(); let dbs = dbs.clone(); 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({ @@ -57,9 +64,8 @@ async fn serve_comments<'a>( templates: Arc, dbs: Dbs, errors: &[String], + mut context: Context, ) -> tide::Result { - dbg!(req.peer_addr()); - let Ok(topic) = req.param("topic") else { 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 mut context = Context::new(); + //let mut context = Context::new(); context.insert("config", &config); context.insert("admin", &admin); context.insert("new_comment_errors", errors); @@ -214,6 +220,7 @@ async fn handle_post_comments( }; let mut errors = Vec::new(); + let mut context = Context::new(); match req.body_form::().await? { CommentQuery::NewComment(query) => { @@ -281,11 +288,15 @@ async fn handle_post_comments( .map_err(|e| error!("Adding pending comment: {:?}", e)) .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( diff --git a/templates/comments.html b/templates/comments.html index 4b669bf..d9757a1 100644 --- a/templates/comments.html +++ b/templates/comments.html @@ -47,11 +47,11 @@ {% endif %} -
+
-
+

-
+