app: Store both household display name & id

This commit is contained in:
traxys 2023-05-29 12:36:21 +02:00
parent d0313af5ba
commit dd266dccfd
4 changed files with 21 additions and 9 deletions

2
Cargo.lock generated
View file

@ -76,7 +76,9 @@ dependencies = [
"gloo-storage",
"gloo-utils",
"log",
"serde",
"serde_json",
"uuid",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",

View file

@ -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"

View file

@ -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::<String>("household") {
let household = match LocalStorage::get::<HouseholdInfo>("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::<String>("household") {
let household = match LocalStorage::get::<HouseholdInfo>("household") {
Ok(v) => v,
Err(e) => unreachable!("Could not get household: {e:?}"),
};
Self {
token: token.into(),
household: household.into(),
household,
}
}
}

View file

@ -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<MenuEntry>,
current: Route,
household: AttrValue,
household: HouseholdInfo,
children: Children,
}
@ -100,7 +100,7 @@ fn Sidebar(props: &SidebarProps) -> Html {
>
<i class={classes!("fs-4", "bi-house-door-fill")}></i>
<strong class={classes!("ms-2", "d-none", "d-sm-inline")}>
{&props.household}
{&props.household.name}
</strong>
</a>
<ul class="dropdown-menu">
@ -121,7 +121,7 @@ fn Sidebar(props: &SidebarProps) -> Html {
#[derive(Properties, PartialEq)]
pub(crate) struct RegaladeSidebarProps {
pub(crate) current: Route,
pub(crate) household: AttrValue,
pub(crate) household: HouseholdInfo,
pub(crate) children: Children,
}