fix hooks
This commit is contained in:
parent
37289c4da9
commit
b6394c41c5
4 changed files with 14 additions and 15 deletions
10
src/api.rs
10
src/api.rs
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use dioxus::signals::{Readable, Writable};
|
||||
use dioxus_sdk::storage::use_persistent;
|
||||
use dioxus_sdk::storage::{get_from_storage, use_persistent, SessionStorage};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::setup::Credentials;
|
||||
|
@ -24,8 +24,8 @@ pub async fn api_get_auth<T>(path: String) -> Result<T, reqwest::Error>
|
|||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let creds = use_persistent("creds", || Credentials::default());
|
||||
let creds = creds.read();
|
||||
let creds =
|
||||
get_from_storage::<SessionStorage, _>("creds".to_owned(), || Credentials::default());
|
||||
let token = creds.token.as_str();
|
||||
let instance = creds.instance_url.as_str();
|
||||
|
||||
|
@ -52,8 +52,8 @@ where
|
|||
T: DeserializeOwned,
|
||||
X: Serialize,
|
||||
{
|
||||
let creds = use_persistent("creds", || Credentials::default());
|
||||
let creds = creds.read();
|
||||
let creds =
|
||||
get_from_storage::<SessionStorage, _>("creds".to_owned(), || Credentials::default());
|
||||
let token = creds.token.as_str();
|
||||
let instance = creds.instance_url.as_str();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use api::{Item, Transaction};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_material_icons::{MaterialIcon, MaterialIconStylesheet};
|
||||
use dioxus_sdk::storage::use_persistent;
|
||||
use dioxus_sdk::storage::{get_from_storage, use_persistent, SessionStorage};
|
||||
use qrscan::QRCodeScanPage;
|
||||
use setup::{Credentials, SetupPage};
|
||||
|
||||
|
@ -61,9 +61,7 @@ pub fn try_recover_api() -> crate::api::API {
|
|||
}
|
||||
|
||||
pub async fn fetch_api() {
|
||||
let res = use_persistent("creds", || Credentials::default())
|
||||
.read()
|
||||
.clone();
|
||||
let res = get_from_storage::<SessionStorage, _>("creds".to_owned(), || Credentials::default());
|
||||
if !res.empty() {
|
||||
let api = api::API::new(res.instance_url.clone()).await;
|
||||
*crate::API.write() = Some(api);
|
||||
|
|
|
@ -16,8 +16,8 @@ pub fn QRCodeScanPage(result: Signal<String>, show: Signal<bool>) -> Element {
|
|||
let imurl = use_signal(|| String::new());
|
||||
let mut imurl2 = imurl.clone();
|
||||
|
||||
if *show.read() {
|
||||
use_effect(move || {
|
||||
use_effect(move || {
|
||||
if *show.read() {
|
||||
let window = window().unwrap();
|
||||
let nav = window.navigator();
|
||||
let media_devices = nav.media_devices().unwrap();
|
||||
|
@ -88,8 +88,8 @@ pub fn QRCodeScanPage(result: Signal<String>, show: Signal<bool>) -> Element {
|
|||
TimeoutFuture::new(16).await;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rsx! {
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use dioxus::prelude::*;
|
||||
use dioxus_sdk::storage::use_persistent;
|
||||
use dioxus_sdk::storage::{new_storage, use_persistent, SessionStorage};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
@ -45,7 +45,8 @@ pub fn SetupPage() -> Element {
|
|||
evt.prevent_default();
|
||||
|
||||
if validate_form() {
|
||||
let mut creds = use_persistent("creds", || Credentials::default());
|
||||
let mut creds =
|
||||
new_storage::<SessionStorage, _>("creds".to_string(), || Credentials::default());
|
||||
|
||||
spawn(async move {
|
||||
let api = crate::api::API::new(creds.read().instance_url.clone()).await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue