diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-11-05 18:06:54 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-11-05 18:37:09 -0400 |
commit | 50d6ef8ad0f344c9b510c6752119fa5983629d95 (patch) | |
tree | fedf2e0569750353a352500ac0ad85034828930d /webapp/src/main.rs | |
parent | 2d9d37bd5e4770a05cae780f2113266f3fdd0915 (diff) |
Add table view and go to table automatically
Diffstat (limited to 'webapp/src/main.rs')
-rw-r--r-- | webapp/src/main.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/webapp/src/main.rs b/webapp/src/main.rs index 4ba8e5f..b275b49 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -8,7 +8,7 @@ use yew_router::prelude::*; pub mod bridge_engine; pub mod card; pub mod components; -use components::{AppContextProvider, AppContext, Game, ErrorInfo}; +use components::{AppContextProvider, AppContext, Game, ErrorInfo, Table}; use gloo_net::http::Request; extern crate wee_alloc; @@ -16,12 +16,14 @@ extern crate wee_alloc; #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; #[derive(Clone, Routable, PartialEq)] - + enum Route { #[at("/")] Home, #[at("/playground")] Playground, + #[at("/table/:id")] + Table { id: Uuid, }, } fn main() { @@ -47,6 +49,8 @@ pub fn app() -> Html { fn home() -> Html { let ctx = use_context::<Rc<AppContext>>().unwrap(); + info!("User: {:#?}", ctx.user); + let user = match &ctx.user { Some(userinfo) => html! { <p>{ format!("Logged in as {}", userinfo.username) }</p> @@ -54,6 +58,11 @@ fn home() -> Html { None => html! { <p><a href="/api/login">{ "Log in" }</a></p> }, }; + if let Some(table) = ctx.user.as_ref().and_then(|u| u.table.as_ref() ) { + let history = use_history().unwrap(); + history.push(Route::Table { id: table.id }); + } + let create_table = Callback::from(|_| { wasm_bindgen_futures::spawn_local(async move { let response = Request::post("/api/table").send().await.unwrap(); @@ -82,6 +91,9 @@ fn switch(routes: &Route) -> Html { Route::Playground => html! { <div class="game-layout"><Game /></div> }, + Route::Table { id } => html! { + <Table table={ protocol::Table { id: *id } } /> + }, } } |