diff --git a/actix_mvc_app/src/controllers/governance.rs b/actix_mvc_app/src/controllers/governance.rs index f0795e9..0a4d032 100644 --- a/actix_mvc_app/src/controllers/governance.rs +++ b/actix_mvc_app/src/controllers/governance.rs @@ -196,9 +196,13 @@ impl GovernanceController { /// Handles the proposal detail page route pub async fn proposal_detail( path: web::Path, + req: actix_web::HttpRequest, tmpl: web::Data, session: Session, ) -> Result { + // Extract query parameters from the request + let query_str = req.query_string(); + let vote_success = query_str.contains("vote_success=true"); let proposal_id = path.into_inner(); let mut ctx = tera::Context::new(); ctx.insert("active_page", "governance"); @@ -220,6 +224,11 @@ impl GovernanceController { // Calculate voting results directly from the proposal let results = Self::calculate_voting_results_from_proposal(&proposal); ctx.insert("results", &results); + + // Check if vote_success parameter is present and add success message + if vote_success { + ctx.insert("success", "Your vote has been successfully recorded!"); + } render_template(&tmpl, "governance/proposal_detail.html", &ctx) } else { @@ -392,18 +401,10 @@ impl GovernanceController { form.comment.as_ref().map(|s| s.to_string()), // Pass the comment from the form ) { Ok(updated_proposal) => { - ctx.insert("proposal", &updated_proposal); - ctx.insert("success", "Your vote has been recorded!"); - - // Extract votes directly from the updated proposal - let votes = Self::extract_votes_from_proposal(&updated_proposal); - ctx.insert("votes", &votes); - - // Calculate voting results directly from the updated proposal - let results = Self::calculate_voting_results_from_proposal(&updated_proposal); - ctx.insert("results", &results); - - render_template(&tmpl, "governance/proposal_detail.html", &ctx) + // Redirect to the proposal detail page with a success message + return Ok(HttpResponse::Found() + .append_header(("Location", format!("/governance/proposals/{}?vote_success=true", proposal_id))) + .finish()); } Err(e) => { ctx.insert("error", &format!("Failed to submit vote: {}", e)); diff --git a/actix_mvc_app/src/views/governance/proposal_detail.html b/actix_mvc_app/src/views/governance/proposal_detail.html index f7c3303..e6f8323 100644 --- a/actix_mvc_app/src/views/governance/proposal_detail.html +++ b/actix_mvc_app/src/views/governance/proposal_detail.html @@ -240,7 +240,7 @@ -
+
@@ -338,6 +338,23 @@ {% block scripts %}