Skip to content

Commit

Permalink
refactor: load recipes in toplevel app component
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrubek committed Sep 24, 2023
1 parent f73fce7 commit 3f630b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 7 additions & 1 deletion crates/ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{api::resolve_ingredients, routing::Route, state::AppState};
use crate::{
api::{resolve_ingredients, resolve_recipes},
routing::Route,
state::AppState,
};
use dioxus::prelude::*;
use dioxus_router::components::Router;
use wasm_bindgen::prelude::*;
Expand All @@ -16,12 +20,14 @@ fn init_wasm() -> Result<(), JsValue> {

#[wasm_bindgen]
pub fn launch_app() {
wasm_logger::init(wasm_logger::Config::default());
dioxus_web::launch(app);
}

fn app(cx: Scope) -> Element {
use_shared_state_provider(cx, AppState::default);
let app_state = use_shared_state::<AppState>(cx).unwrap();
use_future(cx, (), |_| resolve_recipes(app_state.clone()));
use_future(cx, (), |_| resolve_ingredients(app_state.clone()));

render! {
Expand Down
2 changes: 0 additions & 2 deletions crates/ui/src/routing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{
api::resolve_recipes,
components::{IngredientCreate, Recipe, RecipeCreate},
state::AppState,
util,
Expand Down Expand Up @@ -122,7 +121,6 @@ pub(crate) fn AppIndex(cx: Scope) -> Element {
#[allow(non_snake_case)]
pub(crate) fn AppRecipes(cx: Scope) -> Element {
let app_state = use_shared_state::<AppState>(cx).unwrap();
use_future(cx, (), |_| resolve_recipes(app_state.clone()));

let creating_recipe = use_state(cx, || false);

Expand Down

0 comments on commit 3f630b7

Please sign in to comment.