Gate rendering of the view on having actual recipes available.

This commit is contained in:
Jeremy Wall 2022-02-07 19:58:56 -05:00
parent 22eadb832a
commit ace489924d

View File

@ -37,8 +37,18 @@ enum AppRoutes {
pub fn ui() -> View<G> { pub fn ui() -> View<G> {
let app_service = AppService::new(); let app_service = AppService::new();
console_log!("Starting UI"); console_log!("Starting UI");
create_effect(cloned!((app_service) => move || { // TODO(jwall): We need to ensure that this happens before
spawn_local_in_scope({ // we render the UI below.
view! {
// NOTE(jwall): Set the app_service in our toplevel scope. Children will be able
// to find the service as long as they are a child of this scope.
ContextProvider(ContextProviderProps {
value: app_service.clone(),
children: || view! {
Router(RouterProps::new(HistoryIntegration::new(), move |routes: ReadSignal<AppRoutes>| {
let view = Signal::new(View::empty());
create_effect(cloned!((view) => move || {
spawn_local_in_scope(cloned!((routes, view) => {
let mut app_service = app_service.clone(); let mut app_service = app_service.clone();
async move { async move {
match AppService::fetch_recipes().await { match AppService::fetch_recipes().await {
@ -47,21 +57,10 @@ pub fn ui() -> View<G> {
} }
Err(msg) => console_error!("Failed to get recipes {}", msg), Err(msg) => console_error!("Failed to get recipes {}", msg),
} }
}
});
}));
view! {
// NOTE(jwall): Set the app_service in our toplevel scope. Children will be able
// to find the service as long as they are a child of this scope.
ContextProvider(ContextProviderProps {
value: app_service.clone(),
children: || view! {
Router(RouterProps::new(HistoryIntegration::new(), move |routes: ReadSignal<AppRoutes>| {
let t = create_memo(move || {
console_debug!("Determining route."); console_debug!("Determining route.");
let route = routes.get(); let route = routes.get();
console_debug!("Route {:?}", route); console_debug!("Route {:?}", route);
match route.as_ref() { let t = match route.as_ref() {
AppRoutes::Root => view! { AppRoutes::Root => view! {
Start() Start()
}, },
@ -74,15 +73,18 @@ pub fn ui() -> View<G> {
AppRoutes::NotFound => view! { AppRoutes::NotFound => view! {
"NotFound" "NotFound"
} }
};
view.set(t);
console_debug!("Created our route view effect.");
} }
}); }));
console_debug!("Created our route view memo."); }));
view! { view! {
// NOTE(jwall): The Router component *requires* there to be exactly one node as the root of this view. // NOTE(jwall): The Router component *requires* there to be exactly one node as the root of this view.
// No fragments or missing nodes allowed or it will panic at runtime. // No fragments or missing nodes allowed or it will panic at runtime.
div(class="app") { div(class="app") {
Header() Header()
(t.get().as_ref().clone()) (view.get().as_ref().clone())
} }
} }
})) }))