frontend/src/main.rs

56 lines
1.2 KiB
Rust
Raw Normal View History

2023-09-28 14:54:00 +00:00
mod content;
mod state;
2023-09-28 11:08:15 +00:00
mod topbar;
2023-09-28 14:54:00 +00:00
use content::{error, home::Home};
use state::State;
use std::rc::Rc;
use topbar::TopBar;
2023-09-28 11:08:15 +00:00
use yew::prelude::*;
2023-09-28 12:23:12 +00:00
use yew_router::prelude::*;
2023-09-28 11:08:15 +00:00
2023-09-28 12:23:12 +00:00
#[derive(Clone, Routable, PartialEq)]
enum Route {
#[at("/")]
Home,
#[at("/services")]
Services,
#[at("/community")]
Community,
#[at("/about")]
About,
#[not_found]
#[at("/404")]
NotFound,
}
fn switch(routes: Route) -> Html {
match routes {
2023-09-28 14:54:00 +00:00
Route::Home => html! { <Home/> },
2023-09-28 12:23:12 +00:00
Route::Services => html! {<h1>{ "Services" }</h1>},
Route::Community => html! {<h1>{ "Community" }</h1>},
Route::About => html! {<h1>{ "About" }</h1>},
2023-09-28 14:54:00 +00:00
Route::NotFound => html! { <error::NotFound/> },
2023-09-28 12:23:12 +00:00
}
}
2023-09-28 11:08:15 +00:00
#[function_component]
fn App() -> Html {
2023-09-28 14:54:00 +00:00
let state = use_memo(|_| State::default(), ());
2023-09-28 11:08:15 +00:00
html! {
2023-09-28 14:54:00 +00:00
<ContextProvider<Rc<State>> context={state}>
2023-09-28 12:23:12 +00:00
<TopBar/>
<main>
<BrowserRouter>
<Switch<Route> render={switch} />
</BrowserRouter>
</main>
2023-09-28 14:54:00 +00:00
</ContextProvider<Rc<State>>>
2023-09-28 11:08:15 +00:00
}
}
fn main() {
yew::Renderer::<App>::new().render();
2023-09-28 11:08:15 +00:00
}