From 3d8aca19cc4623906f288a08d24e118dbe5eea72 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Thu, 22 May 2025 17:05:26 +0300 Subject: [PATCH] feat: Improve user experience after voting on proposals - Redirect users to the proposal detail page with a success message after a successful vote, improving feedback. - Automatically remove the success message from the URL after a short time to avoid URL clutter and maintain a clean browsing experience. - Add a success alert message on the proposal detail page to provide immediate visual confirmation of a successful vote. - Improve the visual presentation of the votes list on the proposal detail page by adding top margin for better spacing. --- actix_mvc_app/src/controllers/governance.rs | 25 ++++++++++--------- .../src/views/governance/proposal_detail.html | 19 +++++++++++++- 2 files changed, 31 insertions(+), 13 deletions(-) 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 %}