diff --git a/app/src/api/resources.rs b/app/src/api/resources.rs index f75be77..a5cbbfd 100644 --- a/app/src/api/resources.rs +++ b/app/src/api/resources.rs @@ -104,7 +104,7 @@ pub fn use_entity(entity: T) -> Memo { let id = Signal::derive(move || orig_entity.with_value(|w| w.get_id().clone())); let entity_resource = use_entity_resource::(id.get_untracked()); - create_memo(move |_| match entity_resource.read().flatten() { + create_memo(move |_| match entity_resource().flatten() { Some(entity) => entity, None => orig_entity(), }) diff --git a/app/src/auth/context.rs b/app/src/auth/context.rs index 8d58ae2..4933624 100644 --- a/app/src/auth/context.rs +++ b/app/src/auth/context.rs @@ -54,10 +54,10 @@ impl Auth { #[cfg(not(debug_assertions))] LocalStorage::set(TOKEN_STORAGE_KEY, new_token.clone()).unwrap(); - let navigate = use_navigate(self.cx); - self.cx.batch(|| { + let navigate = use_navigate(); + batch(|| { (self.set_token)(Token(Some(new_token))); - navigate("/", Default::default()).unwrap(); + navigate("/", Default::default()); }); }); } @@ -66,10 +66,10 @@ impl Auth { #[cfg(not(debug_assertions))] LocalStorage::delete(TOKEN_STORAGE_KEY); - let navigate = use_navigate(self.cx); - self.cx.batch(|| { + let navigate = use_navigate(); + batch(|| { (self.set_token)(Token(None)); - navigate("/", Default::default()).unwrap(); + navigate("/", Default::default()); }); } } diff --git a/app/src/auth/guard.rs b/app/src/auth/guard.rs index a2d925a..4da836e 100644 --- a/app/src/auth/guard.rs +++ b/app/src/auth/guard.rs @@ -11,17 +11,17 @@ pub fn create_auth_guard() { // workaround for navigating during initial routing // https://docs.rs/leptos_router/0.4.2/leptos_router/fn.use_navigate.html#panics request_animation_frame(move || { - navigate("/login", Default::default()).unwrap(); + navigate("/login", Default::default()); }); } }); let settings = create_settings_resource(); create_effect(move |_| { - if let Some(Err(_)) = settings.read() { + if let Some(Err(_)) = settings() { let navigate = use_navigate(); // TODO handle other errors than "unauthenticated" request_animation_frame(move || { - navigate("/login", Default::default()).unwrap(); + navigate("/login", Default::default()); }); } }); diff --git a/app/src/components/add_button.rs b/app/src/components/add_button.rs index 3f5daa7..6252dd7 100644 --- a/app/src/components/add_button.rs +++ b/app/src/components/add_button.rs @@ -38,7 +38,7 @@ pub fn AddButton() -> impl IntoView { view! {
impl IntoView {
"Select a page" - { page.name } - - } - } - /> + let:page + > + + impl IntoView { let (selected_page, set_selected_page) = create_signal::>(None); create_effect(move |_| { pages.with(move |pages| { - if let Some(sel) = selected_page.get_untracked() { - if !pages.iter().any(|p| p.id == sel.id) { - // selected page doesn't exist anymore, was probably deleted. - // set it to the first page (or none). - set_selected_page(pages.iter().next().cloned()); - }; - } else if let Some(first_page) = pages.iter().next() { - // no page was selected, but a page exists. select it. - set_selected_page(Some(first_page.clone())); + if let Some(pages) = pages { + if let Some(sel) = selected_page.get_untracked() { + if !pages.iter().any(|p| p.id == sel.id) { + // selected page doesn't exist anymore, was probably deleted. + // set it to the first page (or none). + set_selected_page(pages.iter().next().cloned()); + }; + } else if let Some(first_page) = pages.iter().next() { + // no page was selected, but a page exists. select it. + set_selected_page(Some(first_page.clone())); + } } }); }); @@ -47,22 +49,24 @@ pub fn Home() -> impl IntoView {
} - } - /> + let:page + > + { + let id = store_value( page.id.clone()); + let is_selected = Signal::derive( move || { + selected_page().is_some_and(|sp| sp.id == id()) + }); + let select = SignalSetter::map( move |p| set_selected_page(Some(p))); + view! { } + } + diff --git a/app/src/components/page.rs b/app/src/components/page.rs index 8d139ea..84ae0b8 100644 --- a/app/src/components/page.rs +++ b/app/src/components/page.rs @@ -13,12 +13,12 @@ pub fn Page(page: Signal) -> impl IntoView {
} - } - /> + let:widget + > + +
} diff --git a/app/src/components/page_tab.rs b/app/src/components/page_tab.rs index a210752..7857c64 100644 --- a/app/src/components/page_tab.rs +++ b/app/src/components/page_tab.rs @@ -53,13 +53,13 @@ pub fn PageTab( - + - + impl IntoView {
- } - } - /> + let:bookmark + > + +
- + - + ( > - { page.name } - - } - } - /> + let:page + > + +