fix hydration error for cancel game button
This commit is contained in:
parent
6b3cce5e37
commit
06294d872e
|
|
@ -1,13 +1,9 @@
|
||||||
use std::{
|
use std::{fs::File, io::Write};
|
||||||
fs::File,
|
|
||||||
io::Write,
|
|
||||||
};
|
|
||||||
|
|
||||||
const STYLESHEET_PATH: &str = "../style/faction.scss";
|
const STYLESHEET_PATH: &str = "../style/faction.scss";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo::rerun-if-changed=../style/main.scss");
|
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 sheet_file = File::create(STYLESHEET_PATH).unwrap();
|
||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,7 @@ pub fn Nav() -> impl IntoView {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let active_game_button = move || {
|
let active_game_button = move || {
|
||||||
let Some(session) = auth.session().get() else {
|
let session = auth.session().get()?;
|
||||||
return None;
|
|
||||||
};
|
|
||||||
if active_game.value().read_untracked().is_none() {
|
if active_game.value().read_untracked().is_none() {
|
||||||
active_game.dispatch(GetActiveGame {
|
active_game.dispatch(GetActiveGame {
|
||||||
token: session.token,
|
token: session.token,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ pub fn HostGamePage(
|
||||||
message: Signal<Option<Srv2Host>>,
|
message: Signal<Option<Srv2Host>>,
|
||||||
reply: WriteSignal<Option<HostMessage>>,
|
reply: WriteSignal<Option<HostMessage>>,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
|
let prefs = expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>().0;
|
||||||
let settings = RwSignal::new(GameSettings::default());
|
let settings = RwSignal::new(GameSettings::default());
|
||||||
let qr_mode = RwSignal::new(false);
|
let qr_mode = RwSignal::new(false);
|
||||||
let players: RwSignal<Box<[PlayerState]>> = RwSignal::new(Box::new([]));
|
let players: RwSignal<Box<[PlayerState]>> = RwSignal::new(Box::new([]));
|
||||||
|
|
@ -75,28 +76,40 @@ pub fn HostGamePage(
|
||||||
().into_any()
|
().into_any()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let cancel = move || {
|
||||||
view! {
|
view! {
|
||||||
<CancelGame reply=reply />
|
<CancelGame reply=reply prefs=prefs />
|
||||||
|
}
|
||||||
|
};
|
||||||
|
view! {
|
||||||
|
{cancel}
|
||||||
{content}
|
{content}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[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 open = RwSignal::new(false);
|
||||||
let prefs = expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>().0;
|
|
||||||
let cancel = move |_| {
|
let cancel = move |_| {
|
||||||
open.set(false);
|
open.set(false);
|
||||||
reply.set(Some(HostMessage::CancelGame));
|
reply.set(Some(HostMessage::CancelGame));
|
||||||
#[cfg(feature = "hydrate")]
|
#[cfg(not(feature = "ssr"))]
|
||||||
|
{
|
||||||
gloo::utils::window()
|
gloo::utils::window()
|
||||||
.location()
|
.location()
|
||||||
.replace("/")
|
.replace("/")
|
||||||
.console_log_warn();
|
.console_log_warn();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let content = move || match prefs.get().show_cancel_game {
|
let derive_hidden = RwSignal::new(false);
|
||||||
true => view! {
|
Effect::new(move || derive_hidden.set(!prefs.get().show_cancel_game));
|
||||||
|
|
||||||
|
let content = move || {
|
||||||
|
view! {
|
||||||
|
<div hidden=move || derive_hidden.get()>
|
||||||
<DialogModal
|
<DialogModal
|
||||||
button_class="cancel-game-button".into()
|
button_class="cancel-game-button".into()
|
||||||
text="cancel game".into()
|
text="cancel game".into()
|
||||||
|
|
@ -107,11 +120,8 @@ fn CancelGame(reply: WriteSignal<Option<HostMessage>>) -> impl IntoView {
|
||||||
"i'm sure, cancel the game."
|
"i'm sure, cancel the game."
|
||||||
</button>
|
</button>
|
||||||
</DialogModal>
|
</DialogModal>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
.into_any(),
|
|
||||||
false => ().into_any(),
|
|
||||||
};
|
};
|
||||||
view! {
|
view! { {content} }
|
||||||
{content}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ use crate::app::{
|
||||||
#[component]
|
#[component]
|
||||||
pub fn UserSettings() -> impl IntoView {
|
pub fn UserSettings() -> impl IntoView {
|
||||||
let auth = expect_context::<Store<AuthContext>>();
|
let auth = expect_context::<Store<AuthContext>>();
|
||||||
|
let (prefs_read, prefs_write) =
|
||||||
|
expect_context::<(Signal<Preferences>, WriteSignal<Preferences>)>();
|
||||||
let log_out = {
|
let log_out = {
|
||||||
let click = move |e: MouseEvent| {
|
let click = move |e: MouseEvent| {
|
||||||
e.prevent_default();
|
e.prevent_default();
|
||||||
|
|
@ -18,8 +20,6 @@ pub fn UserSettings() -> impl IntoView {
|
||||||
};
|
};
|
||||||
view! { <button on:click=click>"log out"</button> }
|
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 {
|
let tutorial_toggle_button = move || match prefs_read.read().tutorials_enabled {
|
||||||
true => view! {
|
true => view! {
|
||||||
<button on:click=move |_| {
|
<button on:click=move |_| {
|
||||||
|
|
@ -34,7 +34,7 @@ pub fn UserSettings() -> impl IntoView {
|
||||||
}
|
}
|
||||||
.into_any(),
|
.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! {
|
true => view! {
|
||||||
<button on:click=move |_| {
|
<button on:click=move |_| {
|
||||||
prefs_write.write().show_cancel_game = false;
|
prefs_write.write().show_cancel_game = false;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ use axum_extra::{
|
||||||
};
|
};
|
||||||
use codee::HybridDecoder;
|
use codee::HybridDecoder;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use futures::FutureExt;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use werewolves_proto::{
|
use werewolves_proto::{
|
||||||
error::ServerError, game::GameId, message::WrappedServerMessage, token::TokenString,
|
error::ServerError, game::GameId, message::WrappedServerMessage, token::TokenString,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue