clean up stuff on disconnect
This commit is contained in:
parent
35afcf7dd4
commit
89344c6042
2 changed files with 185 additions and 171 deletions
|
@ -60,7 +60,9 @@ pub fn Browser() -> impl IntoView {
|
|||
|
||||
view! {
|
||||
<div class="p-1">
|
||||
<Show when=move || connected() fallback=|| view! { <p>Disconnected.</p> }>
|
||||
<h2 class="text-2xl">Game Browser</h2>
|
||||
<div class="p-1">
|
||||
<table class="min-w-full border border-collapse table-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -71,10 +73,10 @@ pub fn Browser() -> impl IntoView {
|
|||
<th class="border-b"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{move || {
|
||||
game_browser_context()
|
||||
.iter()
|
||||
.map(|game| {
|
||||
<For
|
||||
each=move || game_browser_context()
|
||||
key=|game| game.uuid.clone()
|
||||
children=move |game| {
|
||||
view! {
|
||||
<tr>
|
||||
<td class="text-center border-b">{&game.name}</td>
|
||||
|
@ -107,10 +109,8 @@ pub fn Browser() -> impl IntoView {
|
|||
</td>
|
||||
</tr>
|
||||
}
|
||||
})
|
||||
.collect_view()
|
||||
}}
|
||||
|
||||
}
|
||||
/>
|
||||
</table>
|
||||
</div>
|
||||
<hr />
|
||||
|
@ -240,5 +240,7 @@ pub fn Browser() -> impl IntoView {
|
|||
/>
|
||||
</form>
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,9 +54,10 @@ pub fn Websocket() -> impl IntoView {
|
|||
Rc::new(close.clone()),
|
||||
));
|
||||
|
||||
// TODO: This context stuff can probably be done better
|
||||
let connected = move || ready_state.get() == ConnectionReadyState::Open;
|
||||
|
||||
// Contexts for message handler
|
||||
// TODO: This context stuff can probably be done better
|
||||
let (state_summary, set_state_summary) =
|
||||
create_signal::<Option<ServerStateSummary>>(Option::None);
|
||||
let (active_games, set_active_games) = create_signal::<Vec<GameBrowserMeta>>(vec![]);
|
||||
|
@ -70,6 +71,17 @@ pub fn Websocket() -> impl IntoView {
|
|||
unofficial_meta: vec![],
|
||||
});
|
||||
|
||||
create_effect(move |_| {
|
||||
if !connected() {
|
||||
set_active_games.set_untracked(vec![]);
|
||||
set_user_update.set_untracked(None);
|
||||
set_chat_update.set_untracked(None);
|
||||
set_judge_round.set_untracked(None);
|
||||
set_chat_message.set_untracked(None);
|
||||
set_current_game.set_untracked(None);
|
||||
}
|
||||
});
|
||||
|
||||
provide_context::<ReadSignal<CardPacksMeta>>(card_packs_meta);
|
||||
provide_context::<ReadSignal<Option<UserUpdate>>>(user_update);
|
||||
provide_context::<ReadSignal<Option<ChatUpdate>>>(chat_update);
|
||||
|
|
Loading…
Add table
Reference in a new issue