#![allow(clippy::let_unit_value)] // This is triggering on yew html! {}. use yew::prelude::*; use yew_router::prelude::*; pub mod components; pub mod utils; use components::{AppContextProvider, ErrorInfo, OnlineTable}; extern crate wee_alloc; pub mod routing; use crate::{components::use_app_context, routing::Route}; pub mod services; // Use `wee_alloc` as the global allocator. #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; 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_app_context(); 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(move |_| { ctx.create_table(); }) }; html! { <>

{"Bridge App"}

} } #[function_component(Header)] fn header() -> Html { let ctx = use_app_context(); html! { if let Some(error) = &ctx.error() { } } } fn switch(routes: &Route) -> Html { let main = match routes { Route::Home => html! { }, Route::Table { id } => html! { }, }; html! { <>
{ main } } }