fix(web client): sidebar shows login link for anonymous with a nickname
This commit is contained in:
parent
2f40a0a507
commit
91981e6872
6 changed files with 32 additions and 126 deletions
|
|
@ -29,6 +29,12 @@ use trictrac_store::CheckerMove;
|
|||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// Newtype wrappers so context lookup can distinguish signals of the same inner type.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct AnonNickname(pub RwSignal<Option<String>>);
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct AuthEmailVerified(pub RwSignal<bool>);
|
||||
|
||||
fn relay_url() -> String {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
|
|
@ -170,14 +176,14 @@ pub fn App() -> impl IntoView {
|
|||
let auth_username: RwSignal<Option<String>> = RwSignal::new(None);
|
||||
let auth_email_verified: RwSignal<bool> = RwSignal::new(false);
|
||||
provide_context(auth_username);
|
||||
provide_context(auth_email_verified);
|
||||
provide_context(AuthEmailVerified(auth_email_verified));
|
||||
// Set to true once get_me resolves (success or failure) so lobby can
|
||||
// decide immediately whether to show the nickname modal.
|
||||
let auth_loaded: RwSignal<bool> = RwSignal::new(false);
|
||||
provide_context(auth_loaded);
|
||||
// Nickname chosen by an anonymous player; used instead of "Anonymous".
|
||||
let anon_nickname: RwSignal<Option<String>> = RwSignal::new(None);
|
||||
provide_context(anon_nickname);
|
||||
provide_context(AnonNickname(anon_nickname));
|
||||
spawn_local(async move {
|
||||
if let Ok(me) = api::get_me().await {
|
||||
auth_username.set(Some(me.username));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use leptos::prelude::*;
|
|||
use leptos_router::hooks::use_navigate;
|
||||
|
||||
use crate::api;
|
||||
use crate::app::AuthEmailVerified;
|
||||
use crate::i18n::*;
|
||||
|
||||
#[component]
|
||||
|
|
@ -9,8 +10,8 @@ pub fn AccountPage() -> impl IntoView {
|
|||
let i18n = use_i18n();
|
||||
let auth_username =
|
||||
use_context::<RwSignal<Option<String>>>().expect("auth_username context not found");
|
||||
let auth_email_verified =
|
||||
use_context::<RwSignal<bool>>().expect("auth_email_verified context not found");
|
||||
let auth_email_verified = use_context::<AuthEmailVerified>()
|
||||
.expect("auth_email_verified context not found").0;
|
||||
let navigate = use_navigate();
|
||||
|
||||
// Only redirect to profile when the email is actually verified.
|
||||
|
|
@ -107,8 +108,8 @@ fn LoginForm() -> impl IntoView {
|
|||
let i18n = use_i18n();
|
||||
let auth_username =
|
||||
use_context::<RwSignal<Option<String>>>().expect("auth_username context not found");
|
||||
let auth_email_verified =
|
||||
use_context::<RwSignal<bool>>().expect("auth_email_verified context not found");
|
||||
let auth_email_verified = use_context::<AuthEmailVerified>()
|
||||
.expect("auth_email_verified context not found").0;
|
||||
let navigate = use_navigate();
|
||||
|
||||
let login = RwSignal::new(String::new());
|
||||
|
|
@ -177,8 +178,8 @@ fn RegisterForm() -> impl IntoView {
|
|||
let i18n = use_i18n();
|
||||
let auth_username =
|
||||
use_context::<RwSignal<Option<String>>>().expect("auth_username context not found");
|
||||
let auth_email_verified =
|
||||
use_context::<RwSignal<bool>>().expect("auth_email_verified context not found");
|
||||
let auth_email_verified = use_context::<AuthEmailVerified>()
|
||||
.expect("auth_email_verified context not found").0;
|
||||
|
||||
let username = RwSignal::new(String::new());
|
||||
let email = RwSignal::new(String::new());
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use leptos::prelude::*;
|
|||
use leptos_router::components::A;
|
||||
use leptos_router::hooks::use_query_map;
|
||||
|
||||
use crate::app::{NetCommand, Screen};
|
||||
use crate::app::{AnonNickname, NetCommand, Screen};
|
||||
use crate::i18n::*;
|
||||
|
||||
// ── Room/nickname generation ──────────────────────────────────────────────────
|
||||
|
|
@ -103,7 +103,7 @@ pub fn LobbyPage() -> impl IntoView {
|
|||
let cmd_tx = use_context::<UnboundedSender<NetCommand>>().expect("NetCommand sender");
|
||||
let auth_username = use_context::<RwSignal<Option<String>>>().expect("auth_username context");
|
||||
let auth_loaded = use_context::<RwSignal<bool>>().expect("auth_loaded context");
|
||||
let anon_nickname = use_context::<RwSignal<Option<String>>>().expect("anon_nickname context");
|
||||
let anon_nickname = use_context::<AnonNickname>().expect("anon_nickname context").0;
|
||||
let query = use_query_map();
|
||||
|
||||
let view_state: RwSignal<LobbyView> = RwSignal::new(LobbyView::Idle);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use leptos::prelude::*;
|
|||
use leptos_router::hooks::use_query_map;
|
||||
|
||||
use crate::api;
|
||||
use crate::app::AuthEmailVerified;
|
||||
use crate::i18n::*;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
|
@ -16,8 +17,8 @@ pub fn VerifyEmailPage() -> impl IntoView {
|
|||
let i18n = use_i18n();
|
||||
let auth_username =
|
||||
use_context::<RwSignal<Option<String>>>().expect("auth_username context not found");
|
||||
let auth_email_verified =
|
||||
use_context::<RwSignal<bool>>().expect("auth_email_verified context not found");
|
||||
let auth_email_verified = use_context::<AuthEmailVerified>()
|
||||
.expect("auth_email_verified context not found").0;
|
||||
|
||||
let query = use_query_map();
|
||||
let token = query.with(|m| m.get("token").map(|s| s.to_string()).unwrap_or_default());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue