Refactor route and template organisation #28

Merged
glyph merged 16 commits from route_reorganisation into main 2021-11-16 07:43:38 +00:00
2 changed files with 41 additions and 0 deletions
Showing only changes of commit 61828082fd - Show all commits

View File

@ -0,0 +1,41 @@
use rocket::{get, request::FlashMessage, serde::Serialize};
use rocket_dyn_templates::Template;
use crate::routes::authentication::Authenticated;
// HELPERS AND ROUTES FOR /settings/scuttlebutt
#[derive(Debug, Serialize)]
pub struct ScuttlebuttSettingsContext {
pub back: Option<String>,
pub title: Option<String>,
pub flash_name: Option<String>,
pub flash_msg: Option<String>,
}
impl ScuttlebuttSettingsContext {
pub fn build() -> ScuttlebuttSettingsContext {
ScuttlebuttSettingsContext {
back: None,
title: None,
flash_name: None,
flash_msg: None,
}
}
}
/// Scuttlebutt settings menu.
#[get("/")]
pub fn ssb_settings_menu(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
let mut context = ScuttlebuttSettingsContext::build();
// set back icon link to network route
context.back = Some("/settings".to_string());
context.title = Some("Scuttlebutt Settings".to_string());
// check to see if there is a flash message to display
if let Some(flash) = flash {
// add flash message contents to the context object
context.flash_name = Some(flash.kind().to_string());
context.flash_msg = Some(flash.message().to_string());
};
Template::render("settings/scuttlebutt", &context)
}