feat: merge web-user-portal & web-game
This commit is contained in:
parent
9cc605409e
commit
557f0249f8
34 changed files with 5562 additions and 10 deletions
51
clients/web/src/nav.rs
Normal file
51
clients/web/src/nav.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use leptos::prelude::*;
|
||||
use leptos::task::spawn_local;
|
||||
use leptos_router::components::A;
|
||||
|
||||
use crate::api;
|
||||
use crate::app::Screen;
|
||||
use crate::i18n::*;
|
||||
|
||||
#[component]
|
||||
pub fn SiteNav() -> impl IntoView {
|
||||
let i18n = use_i18n();
|
||||
let screen = use_context::<RwSignal<Screen>>().expect("Screen context not found");
|
||||
let auth_username =
|
||||
use_context::<RwSignal<Option<String>>>().expect("auth_username context not found");
|
||||
|
||||
let is_game_active =
|
||||
move || !matches!(screen.get(), Screen::Login { .. });
|
||||
|
||||
let logout = move |_| {
|
||||
spawn_local(async move {
|
||||
let _ = api::post_logout().await;
|
||||
auth_username.set(None);
|
||||
});
|
||||
};
|
||||
|
||||
view! {
|
||||
<nav class="site-nav" class:hidden=is_game_active>
|
||||
<A href="/" attr:class="site-nav-brand">"Trictrac"</A>
|
||||
<div class="site-nav-spacer" />
|
||||
<div class="lang-switcher">
|
||||
<button
|
||||
class:lang-active=move || i18n.get_locale() == Locale::en
|
||||
on:click=move |_| i18n.set_locale(Locale::en)
|
||||
>"EN"</button>
|
||||
<button
|
||||
class:lang-active=move || i18n.get_locale() == Locale::fr
|
||||
on:click=move |_| i18n.set_locale(Locale::fr)
|
||||
>"FR"</button>
|
||||
</div>
|
||||
{move || match auth_username.get() {
|
||||
Some(u) => view! {
|
||||
<A href=format!("/profile/{u}")>{ u.clone() }</A>
|
||||
<button class="site-nav-btn" on:click=logout>{t!(i18n, sign_out)}</button>
|
||||
}.into_any(),
|
||||
None => view! {
|
||||
<A href="/account">{t!(i18n, sign_in)}</A>
|
||||
}.into_any(),
|
||||
}}
|
||||
</nav>
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue