rm dioxus-sdk storage + localstorage

This commit is contained in:
JMARyA 2025-06-08 17:43:48 +02:00
parent b6394c41c5
commit f16be1536c
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
19 changed files with 49 additions and 2165 deletions

View file

@ -1,10 +1,10 @@
use std::collections::HashMap;
use dioxus::signals::{Readable, Writable};
use dioxus_sdk::storage::{get_from_storage, use_persistent, SessionStorage};
use serde_json::json;
use crate::setup::Credentials;
use crate::store::{load_from_local_storage, save_to_local_storage};
use crate::try_recover_api;
use reqwest::header::{HeaderMap, HeaderValue};
@ -24,8 +24,7 @@ pub async fn api_get_auth<T>(path: String) -> Result<T, reqwest::Error>
where
T: DeserializeOwned,
{
let creds =
get_from_storage::<SessionStorage, _>("creds".to_owned(), || Credentials::default());
let creds = load_from_local_storage::<Credentials>("creds").unwrap_or_default();
let token = creds.token.as_str();
let instance = creds.instance_url.as_str();
@ -52,8 +51,7 @@ where
T: DeserializeOwned,
X: Serialize,
{
let creds =
get_from_storage::<SessionStorage, _>("creds".to_owned(), || Credentials::default());
let creds = load_from_local_storage::<Credentials>("creds").unwrap_or_default();
let token = creds.token.as_str();
let instance = creds.instance_url.as_str();
@ -94,13 +92,9 @@ impl API {
let flow_info: HashMap<String, FlowInfo> =
api_get_auth("/flows".to_string()).await.unwrap();
let mut p_items = use_persistent("api_items", || Vec::<Item>::new());
p_items.set(items.clone());
let mut p_locations =
use_persistent("api_locations", || HashMap::<String, Location>::new());
p_locations.set(locations.clone());
let mut p_flowinfo = use_persistent("api_flow_info", || HashMap::<String, FlowInfo>::new());
p_flowinfo.set(flow_info.clone());
save_to_local_storage("api_items", items.clone());
save_to_local_storage("api_locations", locations.clone());
save_to_local_storage("api_flow_info", flow_info.clone());
Self {
instance,
@ -112,19 +106,12 @@ impl API {
pub fn try_recover() -> Self {
Self {
instance: use_persistent("creds", || Credentials::default())
.read()
.instance_url
.clone(),
items: use_persistent("api_items", || Vec::<Item>::new())
.read()
.clone(),
locations: use_persistent("api_locations", || HashMap::<String, Location>::new())
.read()
.clone(),
flow_info: use_persistent("api_flow_info", || HashMap::<String, FlowInfo>::new())
.read()
.clone(),
instance: load_from_local_storage::<Credentials>("creds")
.unwrap_or_default()
.instance_url,
items: load_from_local_storage("api_items").unwrap_or_default(),
locations: load_from_local_storage("api_locations").unwrap_or_default(),
flow_info: load_from_local_storage("api_flow_info").unwrap_or_default(),
}
}