aex/src/app.rs

88 lines
2.5 KiB
Rust
Raw Normal View History

2025-09-11 05:43:59 +00:00
use leptos::prelude::*;
2025-09-20 08:04:51 +00:00
use leptos_meta::{ provide_meta_context, Stylesheet, Title };
2025-09-11 05:43:59 +00:00
use leptos_router::{
2025-09-20 08:04:51 +00:00
components::{ Route, Router, Routes },
2025-09-11 05:43:59 +00:00
StaticSegment, WildcardSegment,
};
2025-09-20 08:06:39 +00:00
use crate::{
components::{
header::Header,
nav::Nav,
sidebar::Sidebar,
Character,
Inventories,
Wiki
},
prelude::*
};
2025-09-11 07:27:57 +00:00
2025-09-11 05:43:59 +00:00
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
2025-09-11 21:44:46 +00:00
provide_context(Store::new(Dashboard::mock()));
console_error_panic_hook::set_once();
2025-09-11 05:43:59 +00:00
view! {
// injects a stylesheet into the document <head>
// id=leptos means cargo-leptos will hot-reload this stylesheet
<Stylesheet id="leptos" href="/pkg/aex.css"/>
// sets the document title
2025-09-20 08:06:39 +00:00
<Title text="aex"/>
2025-09-11 05:43:59 +00:00
// content for this welcome page
<Router>
<div class="wrapper">
2025-09-11 21:44:46 +00:00
<Header />
<Sidebar />
2025-09-11 05:43:59 +00:00
<main>
2025-09-20 08:06:39 +00:00
<Nav />
2025-09-11 05:43:59 +00:00
<Routes fallback=move || "Not found.">
2025-09-20 08:06:39 +00:00
<Route path=StaticSegment("") view=Character/>
<Route path=StaticSegment("inv") view=Inventories/>
<Route path=StaticSegment("wiki") view=Wiki />
2025-09-11 05:43:59 +00:00
<Route path=WildcardSegment("any") view=NotFound/>
</Routes>
</main>
</div>
2025-09-11 05:43:59 +00:00
</Router>
}
}
/// Renders the home page of your application.
#[component]
fn HomePage() -> impl IntoView {
// Creates a reactive value to update the button
let count = RwSignal::new(0);
let on_click = move |_| *count.write() += 1;
view! {
<h1>"Welcome to Leptos!"</h1>
<button on:click=on_click>"Click Me: " {count}</button>
}
}
/// 404 - Not Found
#[component]
fn NotFound() -> impl IntoView {
// set an HTTP status code 404
// this is feature gated because it can only be done during
// initial server-side rendering
// if you navigate to the 404 page subsequently, the status
// code will not be set because there is not a new HTTP request
// to the server
#[cfg(feature = "ssr")]
{
// this can be done inline because it's synchronous
// if it were async, we'd use a server function
let resp = expect_context::<leptos_actix::ResponseOptions>();
resp.set_status(actix_web::http::StatusCode::NOT_FOUND);
}
view! {
<h1>"Not Found"</h1>
}
}