From 50d6ef8ad0f344c9b510c6752119fa5983629d95 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 5 Nov 2022 18:06:54 -0400 Subject: Add table view and go to table automatically --- webapp/src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'webapp/src/main.rs') 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::>().unwrap(); + info!("User: {:#?}", ctx.user); + let user = match &ctx.user { Some(userinfo) => html! {

{ format!("Logged in as {}", userinfo.username) }

@@ -54,6 +58,11 @@ fn home() -> Html { None => html! {

{ "Log in" }

}, }; + 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! {
}, + Route::Table { id } => html! { + + }, } } -- cgit v1.2.3