use std::rc::Rc; #[allow(unused_imports)] use log::{debug, error, info, warn}; use uuid::Uuid; use yew::prelude::*; use yew_router::prelude::*; pub mod bridge_engine; pub mod card; pub mod components; use components::{AppContextProvider, AppContext, Game, ErrorInfo, Table}; use gloo_net::http::Request; extern crate wee_alloc; // Use `wee_alloc` as the global allocator. #[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() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); wasm_logger::init(wasm_logger::Config::new(log::Level::Debug)); yew::start_app::(); } #[function_component(App)] pub fn app() -> Html { html! { <> render={Switch::render(switch)} /> } } #[function_component(Home)] 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) }

}, 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(); let table_id: Uuid = response.json().await.unwrap(); info!("Created table {table_id}"); }); }); html! { <> if let Some(error) = &ctx.error { }
  • { user }
  • to={Route::Playground}>{ "Playground" }>
} } fn switch(routes: &Route) -> Html { match routes { Route::Home => html!{ }, Route::Playground => html! {
}, Route::Table { id } => html! { }, } } #[cfg(test)] mod tests { pub fn test_setup() { dotenv::dotenv().ok(); let _ = env_logger::builder().is_test(true).try_init(); } }