|
|
|
|
@ -2,13 +2,28 @@
|
|
|
|
|
//!
|
|
|
|
|
//! Compiled to WebAssembly via Trunk targeting `wasm32-unknown-unknown`.
|
|
|
|
|
//! Runs the Yew single-page application with client-side routing.
|
|
|
|
|
//!
|
|
|
|
|
//! All functional code is gated on `wasm32` — yew, web-sys, and wasm-bindgen
|
|
|
|
|
//! are wasm32-only crates unavailable on native targets.
|
|
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
mod api;
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
mod components;
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
mod pages;
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
mod storage;
|
|
|
|
|
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
use yew::prelude::*;
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
use yew_router::prelude::*;
|
|
|
|
|
|
|
|
|
|
/// Application routes matching the frontend route definitions in the design spec.
|
|
|
|
|
///
|
|
|
|
|
/// Routes map to page components. The `NotFound` variant catches all unmatched paths.
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
#[derive(Clone, Routable, PartialEq)]
|
|
|
|
|
pub enum Route {
|
|
|
|
|
/// Home page — displays a random quote.
|
|
|
|
|
@ -33,6 +48,7 @@ pub enum Route {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Route switch function — maps each `Route` variant to its page component.
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
fn switch(routes: Route) -> Html {
|
|
|
|
|
match routes {
|
|
|
|
|
Route::Home => html! { <pages::home::HomePage /> },
|
|
|
|
|
@ -54,6 +70,7 @@ fn switch(routes: Route) -> Html {
|
|
|
|
|
///
|
|
|
|
|
/// Wraps the entire application in a `BrowserRouter` and renders the
|
|
|
|
|
/// route-switched page components via `Switch`.
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
#[function_component(App)]
|
|
|
|
|
fn app() -> Html {
|
|
|
|
|
html! {
|
|
|
|
|
@ -72,11 +89,15 @@ fn app() -> Html {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// WASM entry point — called by the Trunk-generated JS bootstrap.
|
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
|
fn main() {
|
|
|
|
|
yew::Renderer::<App>::new().render();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod api;
|
|
|
|
|
mod components;
|
|
|
|
|
mod pages;
|
|
|
|
|
mod storage;
|
|
|
|
|
/// Stub entry point for native targets.
|
|
|
|
|
///
|
|
|
|
|
/// The UI binary is only meaningful when compiled for wasm32 via Trunk.
|
|
|
|
|
/// This stub satisfies the Rust binary requirement on other targets.
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
|
fn main() {}
|
|
|
|
|
|