fix hydration error for cancel game button

This commit is contained in:
emilis 2026-02-18 00:54:09 +00:00
parent 6b3cce5e37
commit 06294d872e
No known key found for this signature in database
5 changed files with 31 additions and 28 deletions

View File

@ -1,13 +1,9 @@
use std::{
fs::File,
io::Write,
};
use std::{fs::File, io::Write};
const STYLESHEET_PATH: &str = "../style/faction.scss";
fn main() {
println!("cargo::rerun-if-changed=../style/main.scss");
println!("cargo::rerun-if-changed=../target/site/pkg/werewolves.wasm");
let mut sheet_file = File::create(STYLESHEET_PATH).unwrap();
let mut out = String::new();

View File

@ -82,9 +82,7 @@ pub fn Nav() -> impl IntoView {
})
};
let active_game_button = move || {
let Some(session) = auth.session().get() else {
return None;
};
let session = auth.session().get()?;
if active_game.value().read_untracked().is_none() {
active_game.dispatch(GetActiveGame {
token: session.token,

View File

@ -20,6 +20,7 @@ pub fn HostGamePage(
message: Signal<Option<Srv2Host>>,
reply: WriteSignal<Option<HostMessage>>,
) -> impl IntoView {
let prefs = expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>().0;
let settings = RwSignal::new(GameSettings::default());
let qr_mode = RwSignal::new(false);
let players: RwSignal<Box<[PlayerState]>> = RwSignal::new(Box::new([]));
@ -75,28 +76,40 @@ pub fn HostGamePage(
().into_any()
}
};
let cancel = move || {
view! {
<CancelGame reply=reply />
<CancelGame reply=reply prefs=prefs />
}
};
view! {
{cancel}
{content}
}
}
#[component]
fn CancelGame(reply: WriteSignal<Option<HostMessage>>) -> impl IntoView {
fn CancelGame(
reply: WriteSignal<Option<HostMessage>>,
prefs: Signal<Preferences>,
) -> impl IntoView {
let open = RwSignal::new(false);
let prefs = expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>().0;
let cancel = move |_| {
open.set(false);
reply.set(Some(HostMessage::CancelGame));
#[cfg(feature = "hydrate")]
#[cfg(not(feature = "ssr"))]
{
gloo::utils::window()
.location()
.replace("/")
.console_log_warn();
}
};
let content = move || match prefs.get().show_cancel_game {
true => view! {
let derive_hidden = RwSignal::new(false);
Effect::new(move || derive_hidden.set(!prefs.get().show_cancel_game));
let content = move || {
view! {
<div hidden=move || derive_hidden.get()>
<DialogModal
button_class="cancel-game-button".into()
text="cancel game".into()
@ -107,11 +120,8 @@ fn CancelGame(reply: WriteSignal<Option<HostMessage>>) -> impl IntoView {
"i'm sure, cancel the game."
</button>
</DialogModal>
</div>
}
.into_any(),
false => ().into_any(),
};
view! {
{content}
}
view! { {content} }
}

View File

@ -10,6 +10,8 @@ use crate::app::{
#[component]
pub fn UserSettings() -> impl IntoView {
let auth = expect_context::<Store<AuthContext>>();
let (prefs_read, prefs_write) =
expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>();
let log_out = {
let click = move |e: MouseEvent| {
e.prevent_default();
@ -18,8 +20,6 @@ pub fn UserSettings() -> impl IntoView {
};
view! { <button on:click=click>"log out"</button> }
};
let (prefs_read, prefs_write) =
expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>();
let tutorial_toggle_button = move || match prefs_read.read().tutorials_enabled {
true => view! {
<button on:click=move |_| {
@ -34,7 +34,7 @@ pub fn UserSettings() -> impl IntoView {
}
.into_any(),
};
let cancel_game_toggle_button = move || match prefs_read.read().show_cancel_game {
let cancel_game_toggle_button = move || match prefs_read.get().show_cancel_game {
true => view! {
<button on:click=move |_| {
prefs_write.write().show_cancel_game = false;

View File

@ -24,7 +24,6 @@ use axum_extra::{
};
use codee::HybridDecoder;
use colored::Colorize;
use futures::FutureExt;
use uuid::Uuid;
use werewolves_proto::{
error::ServerError, game::GameId, message::WrappedServerMessage, token::TokenString,