From 5c6fd4b5ae7f44ca2ea8ba7442d427960291a794 Mon Sep 17 00:00:00 2001 From: Franz Dietrich Date: Tue, 25 May 2021 13:38:42 +0200 Subject: [PATCH] document navigation --- app/src/navigation.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/navigation.rs b/app/src/navigation.rs index 68de389..9e3e1a5 100644 --- a/app/src/navigation.rs +++ b/app/src/navigation.rs @@ -3,9 +3,15 @@ use seed::{a, attrs, div, li, nav, ol, prelude::*, Url}; use shared::datatypes::User; use crate::{i18n::I18n, Msg}; + +/// Generate the top navigation menu of all pages. +/// +/// The menu options are translated using the i18n module. #[must_use] pub fn navigation(i18n: &I18n, base_url: &Url, user: &Option) -> Node { + // A shortcut for translating strings. let t = move |key: &str| i18n.translate(key, None); + // Translate the wellcome message let welcome = if let Some(user) = user { i18n.translate( "welcome-user", @@ -16,10 +22,12 @@ pub fn navigation(i18n: &I18n, base_url: &Url, user: &Option) -> Node }; nav![ ol![ + // A button for the homepage, the list of URLs li![a![ attrs! {At::Href => crate::Urls::new(base_url).list_links()}, t("list-links"), ],], + // A button to create a new shortened URL li![a![ attrs! {At::Href => crate::Urls::new(base_url).create_link()}, ev(Ev::Click, |_| Msg::ListLinks( @@ -29,6 +37,7 @@ pub fn navigation(i18n: &I18n, base_url: &Url, user: &Option) -> Node )), t("add-link"), ],], + // A button to create a new user li![a![ attrs! {At::Href => crate::Urls::new(base_url).create_user()}, ev(Ev::Click, |_| Msg::ListUsers( @@ -38,15 +47,18 @@ pub fn navigation(i18n: &I18n, base_url: &Url, user: &Option) -> Node )), t("invite-user"), ],], + // A button to list all users li![a![ attrs! {At::Href => crate::Urls::new(base_url).list_users()}, t("list-users"), ],], ], ol![ + // The Welcome message li![div![welcome]], + // The logout button li![a![ - attrs! {At::Href => "#"}, + attrs! {At::Href => "/admin/logout"}, ev(Ev::Click, |_| Msg::NoMessage), t("logout"), ]]