Update to dioxus 0.4

This commit is contained in:
traxys 2023-08-05 12:54:49 +02:00
parent c36ce14b3b
commit 183f8a75d2
10 changed files with 328 additions and 586 deletions

View file

@ -6,11 +6,16 @@ use std::{
};
use dioxus::prelude::*;
use dioxus_router::use_router;
use dioxus_router::prelude::*;
use gloo_storage::{errors::StorageError, LocalStorage, Storage};
use uuid::Uuid;
use crate::{HouseholdInfo, LoginInfo, RedirectorProps};
use crate::{HouseholdInfo, LoginInfo, Route};
#[derive(Props)]
pub struct RedirectorProps<'a> {
children: Element<'a>,
}
pub struct RefreshHandle {
run: Box<dyn FnOnce()>,
@ -159,12 +164,12 @@ fn FullContextRedirectInner<'a>(cx: Scope<'a, RedirectorProps<'a>>) -> Element {
}
pub fn FullContextRedirect<'a>(cx: Scope<'a, RedirectorProps<'a>>) -> Element {
let router = use_router(cx);
let navigator = use_navigator(cx);
let check_token = match LocalStorage::get::<LoginInfo>("token") {
Ok(_) => true,
Err(StorageError::KeyNotFound(_)) => {
router.navigate_to("/login");
navigator.push(Route::Login);
false
}
Err(e) => unreachable!("Could not get token: {e:?}"),
@ -173,7 +178,7 @@ pub fn FullContextRedirect<'a>(cx: Scope<'a, RedirectorProps<'a>>) -> Element {
let check_household = match LocalStorage::get::<HouseholdInfo>("household") {
Ok(_) => true,
Err(StorageError::KeyNotFound(_)) => {
router.navigate_to("/household_selection");
navigator.push(Route::HouseholdSelection);
false
}
Err(e) => unreachable!("Could not get household: {e:?}"),