summaryrefslogtreecommitdiff
path: root/webapp/src/main.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-11-14 19:49:52 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-11-14 19:49:52 -0500
commit4c0109a8c40012f75e3d0d900c0ef41893cfb4bb (patch)
treee0bf12ffbf5038963f6116250f04f9e820ff8927 /webapp/src/main.rs
parentd4650a3160d52d289686fb59efbf8f0a436b71eb (diff)
Fetch table state from server
Diffstat (limited to 'webapp/src/main.rs')
-rw-r--r--webapp/src/main.rs38
1 files changed, 25 insertions, 13 deletions
diff --git a/webapp/src/main.rs b/webapp/src/main.rs
index 577b720..35e69fd 100644
--- a/webapp/src/main.rs
+++ b/webapp/src/main.rs
@@ -11,7 +11,7 @@ use components::{AppContext, AppContextProvider, ErrorInfo, Game, Table};
use gloo_net::http::Request;
extern crate wee_alloc;
pub mod routing;
-use crate::{routing::Route, components::use_app_context};
+use crate::{components::use_app_context, routing::Route};
use uuid::Uuid;
// Use `wee_alloc` as the global allocator.
@@ -41,8 +41,6 @@ pub fn app() -> Html {
fn home() -> Html {
let ctx = use_app_context();
- info!("User: {:#?}", ctx.user());
-
let user = match &ctx.user() {
Some(userinfo) => html! {
<p>{ format!("Logged in as {}", userinfo.username) }</p>
@@ -56,28 +54,35 @@ fn home() -> Html {
}
let create_table = {
- let ctx = ctx.clone();
- Callback::from(move |_| {
- ctx.create_table();
- })
+ let ctx = ctx.clone();
+ Callback::from(move |_| {
+ ctx.create_table();
+ })
};
+ info!("home(): Error is {:?}", ctx.error());
+
html! {
- <>
- if let Some(error) = &ctx.error() {
- <ErrorInfo ..(*error).clone()/>
- }
<ul>
<li>{ user }</li>
<li><Link<Route> to={Route::Playground}>{ "Playground" }</Link<Route>></li>
<li><button onclick={create_table}>{ "Create table" }</button></li>
</ul>
- </>
+ }
+}
+
+#[function_component(Header)]
+fn header() -> Html {
+ let ctx = use_app_context();
+ html! {
+ if let Some(error) = &ctx.error() {
+ <ErrorInfo ..(*error).clone()/>
+ }
}
}
fn switch(routes: &Route) -> Html {
- match routes {
+ let main = match routes {
Route::Home => html! { <Home/> },
Route::Playground => html! {
<div class="game-layout"><Game /></div>
@@ -85,6 +90,13 @@ fn switch(routes: &Route) -> Html {
Route::Table { id } => html! {
<Table table={ protocol::Table { id: *id } } />
},
+ };
+
+ html! {
+ <>
+ <Header/>
+ { main }
+ </>
}
}