summaryrefslogtreecommitdiff
path: root/webapp
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-11-05 18:06:54 -0400
committerKjetil Orbekk <kj@orbekk.com>2022-11-05 18:37:09 -0400
commit50d6ef8ad0f344c9b510c6752119fa5983629d95 (patch)
treefedf2e0569750353a352500ac0ad85034828930d /webapp
parent2d9d37bd5e4770a05cae780f2113266f3fdd0915 (diff)
Add table view and go to table automatically
Diffstat (limited to 'webapp')
-rw-r--r--webapp/src/components.rs2
-rw-r--r--webapp/src/components/table.rs20
-rw-r--r--webapp/src/main.rs16
3 files changed, 36 insertions, 2 deletions
diff --git a/webapp/src/components.rs b/webapp/src/components.rs
index 60c310e..0326c09 100644
--- a/webapp/src/components.rs
+++ b/webapp/src/components.rs
@@ -11,6 +11,7 @@ mod hand;
mod show_bid;
mod trick_in_play;
mod tricks_played;
+mod table;
pub use self::app_context_provider::*;
pub use self::bidding::*;
@@ -23,6 +24,7 @@ pub use self::show_bid::*;
pub use self::trick_in_play::*;
pub use self::tricks_played::*;
pub use self::error_info::*;
+pub use self::table::*;
pub fn suit_css_class(suit: Suit) -> &'static str {
match suit {
diff --git a/webapp/src/components/table.rs b/webapp/src/components/table.rs
new file mode 100644
index 0000000..8e8b5c8
--- /dev/null
+++ b/webapp/src/components/table.rs
@@ -0,0 +1,20 @@
+use yew::prelude::*;
+
+#[function_component(Table)]
+pub fn table(props: &TableProps) -> Html {
+ // let leave_table = {
+ // Callback::from(move |_| {
+ // });
+ // };
+
+ html! {
+ <>
+ <p>{ format!("This is table {}", props.table.id) }</p>
+ </>
+ }
+}
+
+#[derive(PartialEq, Properties, Clone)]
+pub struct TableProps {
+ pub table: protocol::Table,
+}
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 } } />
+ },
}
}