use leptos::{ IntoView, component, prelude::{ClassAttribute, ElementChild, OnAttribute}, view, }; use leptos_router::{NavigateOptions, components::A, hooks::use_navigate}; use log::info; use rocie_client::models::{Recipe, RecipeParent}; use crate::{ api::{ recipe_parents_toplevel_wrapped, recipe_parents_under_404_wrapped, recipes_by_recipe_parent_id_direct_wrapped, recipes_by_recipe_parent_id_indirect_wrapped, recipes_without_recipe_parent_wrapped, }, components::{ async_fetch::{AsyncFetch, AsyncResource}, catch_errors::CatchErrors, login_wall::LoginWall, site_header::SiteHeader, }, pages::mk_render_parents, }; #[component] pub fn Recipies() -> impl IntoView { view! {
    { AsyncFetch! { @map_error_in_producer from_resource = AsyncResource!( () -> Result<(Vec, Vec), leptos::error::Error> { Ok(( recipe_parents_toplevel_wrapped().await?, recipes_without_recipe_parent_wrapped().await? )) } ), producer = |(parents, toplevel_recipes)| { render_recipe_parents(Some(parents), Some(toplevel_recipes)) }, } }
} } mk_render_parents!( self = render_recipe_parents, parent_type = RecipeParent, item_type = Recipe, value_renderer = render_recipes, under_parent_fetcher = recipe_parents_under_404_wrapped, indirect_fetcher = recipes_by_recipe_parent_id_indirect_wrapped, direct_fetcher = recipes_by_recipe_parent_id_direct_wrapped, ); fn render_recipes(recipes: Vec) -> impl IntoView { recipes .into_iter() .map(|recipe| { let name = recipe.name.clone(); view! {
  • {recipe.name}
  • } }) .collect::>() }