app: Store both household display name & id
This commit is contained in:
parent
d0313af5ba
commit
dd266dccfd
4 changed files with 21 additions and 9 deletions
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue