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 shared::datatypes::User;
|
||||||
|
|
||||||
use crate::{i18n::I18n, Msg};
|
use crate::{i18n::I18n, Msg};
|
||||||
|
|
||||||
|
/// Generate the top navigation menu of all pages.
|
||||||
|
///
|
||||||
|
/// The menu options are translated using the i18n module.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn navigation(i18n: &I18n, base_url: &Url, user: &Option<User>) -> Node<Msg> {
|
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);
|
let t = move |key: &str| i18n.translate(key, None);
|
||||||
|
// Translate the wellcome message
|
||||||
let welcome = if let Some(user) = user {
|
let welcome = if let Some(user) = user {
|
||||||
i18n.translate(
|
i18n.translate(
|
||||||
"welcome-user",
|
"welcome-user",
|
||||||
@ -16,10 +22,12 @@ pub fn navigation(i18n: &I18n, base_url: &Url, user: &Option<User>) -> Node<Msg>
|
|||||||
};
|
};
|
||||||
nav![
|
nav![
|
||||||
ol![
|
ol![
|
||||||
|
// A button for the homepage, the list of URLs
|
||||||
li![a![
|
li![a![
|
||||||
attrs! {At::Href => crate::Urls::new(base_url).list_links()},
|
attrs! {At::Href => crate::Urls::new(base_url).list_links()},
|
||||||
t("list-links"),
|
t("list-links"),
|
||||||
],],
|
],],
|
||||||
|
// A button to create a new shortened URL
|
||||||
li![a![
|
li![a![
|
||||||
attrs! {At::Href => crate::Urls::new(base_url).create_link()},
|
attrs! {At::Href => crate::Urls::new(base_url).create_link()},
|
||||||
ev(Ev::Click, |_| Msg::ListLinks(
|
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"),
|
t("add-link"),
|
||||||
],],
|
],],
|
||||||
|
// A button to create a new user
|
||||||
li![a![
|
li![a![
|
||||||
attrs! {At::Href => crate::Urls::new(base_url).create_user()},
|
attrs! {At::Href => crate::Urls::new(base_url).create_user()},
|
||||||
ev(Ev::Click, |_| Msg::ListUsers(
|
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"),
|
t("invite-user"),
|
||||||
],],
|
],],
|
||||||
|
// A button to list all users
|
||||||
li![a![
|
li![a![
|
||||||
attrs! {At::Href => crate::Urls::new(base_url).list_users()},
|
attrs! {At::Href => crate::Urls::new(base_url).list_users()},
|
||||||
t("list-users"),
|
t("list-users"),
|
||||||
],],
|
],],
|
||||||
],
|
],
|
||||||
ol![
|
ol![
|
||||||
|
// The Welcome message
|
||||||
li![div![welcome]],
|
li![div![welcome]],
|
||||||
|
// The logout button
|
||||||
li![a![
|
li![a![
|
||||||
attrs! {At::Href => "#"},
|
attrs! {At::Href => "/admin/logout"},
|
||||||
ev(Ev::Click, |_| Msg::NoMessage),
|
ev(Ev::Click, |_| Msg::NoMessage),
|
||||||
t("logout"),
|
t("logout"),
|
||||||
]]
|
]]
|
||||||
|
Loading…
Reference in New Issue
Block a user