document navigation
This commit is contained in:
parent
78d147344f
commit
5c6fd4b5ae
@ -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<User>) -> Node<Msg> {
|
||||
// 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<User>) -> Node<Msg>
|
||||
};
|
||||
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<User>) -> Node<Msg>
|
||||
)),
|
||||
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<User>) -> Node<Msg>
|
||||
)),
|
||||
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"),
|
||||
]]
|
||||
|
Loading…
Reference in New Issue
Block a user