fossdb_client/
lib.rs

1mod api;
2mod components;
3mod hooks;
4mod pages;
5
6use dioxus::prelude::*;
7use dioxus_logger::tracing::{info, Level};
8
9use components::{ComparisonBar, Navigation, NotificationContainer};
10use hooks::{use_keyboard_shortcut, KeyPress};
11use pages::{ApiDocs, Home, PackageDetail, Packages, Subscriptions};
12
13#[derive(Clone, Routable, Debug, PartialEq)]
14#[rustfmt::skip]
15enum Route {
16    #[layout(Layout)]
17        #[route("/")]
18        Home {},
19        #[route("/packages")]
20        Packages {},
21        #[route("/packages/:id")]
22        PackageDetail { id: String },
23        #[route("/subscriptions")]
24        Subscriptions {},
25        #[route("/api")]
26        ApiDocs {},
27}
28
29#[component]
30fn Layout() -> Element {
31    let nav = navigator();
32
33    // Keyboard shortcuts
34    use_keyboard_shortcut(
35        KeyPress {
36            key: "1",
37            ctrl: true,
38            shift: false,
39            alt: false,
40        },
41        move || {
42            nav.push(Route::Home {});
43        },
44    );
45
46    use_keyboard_shortcut(
47        KeyPress {
48            key: "2",
49            ctrl: true,
50            shift: false,
51            alt: false,
52        },
53        move || {
54            nav.push(Route::Packages {});
55        },
56    );
57
58    use_keyboard_shortcut(
59        KeyPress {
60            key: "3",
61            ctrl: true,
62            shift: false,
63            alt: false,
64        },
65        move || {
66            nav.push(Route::ApiDocs {});
67        },
68    );
69
70    rsx! {
71        Navigation {}
72        NotificationContainer {}
73        ComparisonBar {}
74        Outlet::<Route> {}
75    }
76}
77
78#[component]
79pub fn App() -> Element {
80    // Provide all context providers
81    use_context_provider(|| Signal::new(hooks::auth::AuthState::default()));
82    use_context_provider(|| Signal::new(hooks::NotificationState::default()));
83    use_context_provider(|| Signal::new(components::ComparisonState::default()));
84
85    rsx! {
86        document::Link { rel: "stylesheet", href: "https://cdn.tailwindcss.com" }
87        document::Link {
88            rel: "stylesheet",
89            href: "https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"
90        }
91        style { {include_str!("styles.css")} }
92
93        div { class: "bg-gradient-to-br from-gray-900 to-gray-800 min-h-screen text-white",
94            Router::<Route> {}
95        }
96    }
97}
98
99pub fn launch() {
100    dioxus_logger::init(Level::INFO).expect("failed to init logger");
101    dioxus::launch(App);
102}