summary refs log tree commit diff stats
path: root/src/pages/home.rs
blob: b9dba64dbb8ea85181bff4c1d3757e85df8aef43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use leptos::{
    IntoView, component,
    error::ErrorBoundary,
    prelude::{ClassAttribute, CollectView, ElementChild, Get, GetUntracked},
    view,
};
use leptos_router::{
    NavigateOptions,
    hooks::{use_navigate, use_query_map},
};

use crate::components::{
    inventory::Inventory, product_overview::ProductOverview, recipies::Recipies,
    site_header::SiteHeader, unit_overview::UnitOverview,
};

#[component]
pub fn Home() -> impl IntoView {
    let query_map = use_query_map().get_untracked();
    let navigate = use_navigate();

    if let Some(path) = query_map.get("path") {
        navigate(&path, NavigateOptions::default());
    }

    view! {
        <ErrorBoundary fallback=|errors| {
            view! {
                <h1>"Uh oh! Something went wrong!"</h1>

                <p>"Errors: "</p>
                // Render a list of errors as strings - good for development purposes
                <ul>
                    {move || {
                        errors
                            .get()
                            .into_iter()
                            .map(|(_, e)| view! { <li>{e.to_string()}</li> })
                            .collect_view()
                    }}
                </ul>
            }
        }>

            <div class="flex flex-col content-start">
                <SiteHeader logo=icondata_io::IoRoseSharp back_location="/" name="Rocie" />
                <Inventory />
                <Recipies />
                <ProductOverview />
                <UnitOverview />
            </div>
        </ErrorBoundary>
    }
}