mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-23 06:19:22 -05:00
feat: optimized routing
This commit is contained in:
parent
9e433c5e67
commit
4a4b1bdf5c
2 changed files with 100 additions and 103 deletions
|
@ -13,33 +13,43 @@ use thaw::*;
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
let is_routing = RwSignal::new(false);
|
|
||||||
let set_is_routing = SignalSetter::map(move |is_routing_data| {
|
|
||||||
is_routing.set(is_routing_data);
|
|
||||||
});
|
|
||||||
provide_meta_context();
|
provide_meta_context();
|
||||||
|
// let (read_theme, _, _) = use_local_storage::<String, FromToStringCodec>("theme");
|
||||||
|
// let theme = RwSignal::new(Theme::from(read_theme.get_untracked()));
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Router set_is_routing>
|
<ConfigProvider>
|
||||||
<TheProvider>
|
<ToasterProvider>
|
||||||
<TheRouter is_routing/>
|
<LoadingBarProvider>
|
||||||
</TheProvider>
|
<TheRouter />
|
||||||
</Router>
|
</LoadingBarProvider>
|
||||||
|
</ToasterProvider>
|
||||||
|
</ConfigProvider>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
|
fn TheRouter() -> impl IntoView {
|
||||||
let loading_bar = LoadingBarInjection::expect_use();
|
let loading_bar = LoadingBarInjection::expect_use();
|
||||||
_ = is_routing.watch(move |is_routing| {
|
let is_routing = RwSignal::new(false);
|
||||||
|
let set_is_routing = SignalSetter::map(move |is_routing_data| {
|
||||||
|
is_routing.set(is_routing_data);
|
||||||
|
});
|
||||||
|
|
||||||
|
Effect::watch(
|
||||||
|
move || is_routing.get(),
|
||||||
|
move |is_routing, _, _| {
|
||||||
if *is_routing {
|
if *is_routing {
|
||||||
loading_bar.start();
|
loading_bar.start();
|
||||||
} else {
|
} else {
|
||||||
loading_bar.finish();
|
loading_bar.finish();
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
|
<Router set_is_routing>
|
||||||
<Routes fallback=|| "404">
|
<Routes fallback=|| "404">
|
||||||
<Route path=path!("/") view=Home/>
|
<Route path=path!("/") view=Home/>
|
||||||
<ParentRoute path=path!("/guide") view=ComponentsPage>
|
<ParentRoute path=path!("/guide") view=ComponentsPage>
|
||||||
|
@ -108,21 +118,6 @@ fn TheRouter(is_routing: RwSignal<bool>) -> impl IntoView {
|
||||||
}
|
}
|
||||||
</ParentRoute>
|
</ParentRoute>
|
||||||
</Routes>
|
</Routes>
|
||||||
}
|
</Router>
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
fn TheProvider(children: Children) -> impl IntoView {
|
|
||||||
// let (read_theme, _, _) = use_local_storage::<String, FromToStringCodec>("theme");
|
|
||||||
// let theme = RwSignal::new(Theme::from(read_theme.get_untracked()));
|
|
||||||
|
|
||||||
view! {
|
|
||||||
<ConfigProvider>
|
|
||||||
<ToasterProvider>
|
|
||||||
<LoadingBarProvider>
|
|
||||||
{children()}
|
|
||||||
</LoadingBarProvider>
|
|
||||||
</ToasterProvider>
|
|
||||||
</ConfigProvider>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,11 @@ fn main() {
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
|
<ConfigProvider>
|
||||||
<Button appearance=ButtonAppearance::Primary>
|
<Button appearance=ButtonAppearance::Primary>
|
||||||
"Primary"
|
"Primary"
|
||||||
</Button>
|
</Button>
|
||||||
|
</ConfigProvider>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
Loading…
Add table
Reference in a new issue