diff --git a/Cargo.lock b/Cargo.lock index eaf054d..ab813f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,7 +76,9 @@ dependencies = [ "gloo-storage", "gloo-utils", "log", + "serde", "serde_json", + "uuid", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", diff --git a/app/Cargo.toml b/app/Cargo.toml index 306e2a8..849c3ab 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -13,7 +13,9 @@ gloo-net = "0.2.6" gloo-storage = "0.2.2" gloo-utils = "0.1.6" log = "0.4.17" +serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" +uuid = "1.3.3" wasm-bindgen = "0.2.86" wasm-bindgen-futures = "0.4.36" web-sys = "0.3.63" diff --git a/app/src/main.rs b/app/src/main.rs index 0073e45..ccf1c48 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -1,6 +1,8 @@ use api::{LoginRequest, LoginResponse}; use gloo_storage::{errors::StorageError, LocalStorage, Storage}; use log::Level; +use serde::{Deserialize, Serialize}; +use uuid::Uuid; use wasm_bindgen::JsCast; use web_sys::HtmlInputElement; use yew::prelude::*; @@ -45,10 +47,16 @@ fn App() -> Html { } } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +struct HouseholdInfo { + id: Uuid, + name: String, +} + #[derive(Debug, Clone)] struct RegaladeGlobalState { token: AttrValue, - household: AttrValue, + household: HouseholdInfo, } impl RegaladeGlobalState { @@ -62,7 +70,7 @@ impl RegaladeGlobalState { Err(e) => unreachable!("Could not get token: {e:?}"), }; - let household = match LocalStorage::get::("household") { + let household = match LocalStorage::get::("household") { Ok(v) => v, Err(StorageError::KeyNotFound(_)) => { navigator.push(&Route::HouseholdSelect); @@ -73,7 +81,7 @@ impl RegaladeGlobalState { Some(Self { token: token.into(), - household: household.into(), + household, }) } @@ -83,14 +91,14 @@ impl RegaladeGlobalState { Err(e) => unreachable!("Could not get token: {e:?}"), }; - let household = match LocalStorage::get::("household") { + let household = match LocalStorage::get::("household") { Ok(v) => v, Err(e) => unreachable!("Could not get household: {e:?}"), }; Self { token: token.into(), - household: household.into(), + household, } } } diff --git a/app/src/sidebar.rs b/app/src/sidebar.rs index 657d6f2..3e6581d 100644 --- a/app/src/sidebar.rs +++ b/app/src/sidebar.rs @@ -1,5 +1,5 @@ use yew::prelude::*; -use crate::Route; +use crate::{Route, HouseholdInfo}; #[derive(PartialEq)] struct MenuEntry { @@ -12,7 +12,7 @@ struct MenuEntry { struct SidebarProps { entries: Vec, current: Route, - household: AttrValue, + household: HouseholdInfo, children: Children, } @@ -100,7 +100,7 @@ fn Sidebar(props: &SidebarProps) -> Html { > - {&props.household} + {&props.household.name}