Files
ticketsystem/frontend/src/lib.rs
schn33fuchs 931bd27c65 Sidebar fix
Styles now actually get applied and sidebar doesn't block content
Also the login page doesn't have a sidebar now
2026-05-02 19:09:41 +02:00

124 lines
3.2 KiB
Rust

mod auth;
mod pages;
use crate::auth::ProtectedRoute;
use crate::pages::*;
use yew::prelude::*;
use yew_router::prelude::*;
#[derive(Clone, PartialEq, Routable)]
enum Route {
#[at("/")]
Home,
#[at("/ticket")]
Ticket,
#[at("/tickets/:id")]
TicketById { id: i32 },
#[at("/tickets")]
AllTickets,
#[at("/register")]
Register,
#[at("/login")]
Login,
#[at("/users")]
AllUsers,
#[at("/users/:id")]
UserByID { id: i16 },
#[at("/diagnostics")]
Diagnostics,
#[at("/denied")]
PermissionDenied,
#[not_found]
#[at("/404")]
NotFound,
}
#[derive(Properties, PartialEq)]
pub struct SidebarShellProps {
pub children: Children,
}
#[component(SidebarShell)]
fn sidebar_shell(props: &SidebarShellProps) -> Html {
html! {
<div class="layout">
<sidebar::Sidebar/>
<main class="content">
{ for props.children.iter() }
</main>
</div>
}
}
fn switch(route: Route) -> Html {
match route {
Route::Home => html! {
<ProtectedRoute admin_page={false}>
<SidebarShell>
<basic_pages::Home/>
</SidebarShell>
</ProtectedRoute>
},
Route::NotFound => html! { <basic_pages::NotFound/> },
Route::Ticket => html! {
<ProtectedRoute admin_page={false}>
<SidebarShell>
<ticket::SubmitTicket/>
</SidebarShell>
</ProtectedRoute>
},
Route::TicketById { id } => html! {
<ProtectedRoute admin_page={true}>
<SidebarShell>
<ticket::TicketByID {id}/>
</SidebarShell>
</ProtectedRoute>
},
Route::AllTickets => html! {
<ProtectedRoute admin_page={false}>
<SidebarShell>
<ticket::AllTickets/>
</SidebarShell>
</ProtectedRoute>
},
Route::Register => html! {
<ProtectedRoute admin_page={true}>
<SidebarShell>
<user::Register/>
</SidebarShell>
</ProtectedRoute>
},
Route::Login => html! { <user::Login/> },
Route::AllUsers => html! {
<ProtectedRoute admin_page={true}>
<SidebarShell>
<user::AllUsers/>
</SidebarShell>
</ProtectedRoute>
},
Route::UserByID { id } => html! {
<ProtectedRoute admin_page={true}>
<SidebarShell>
<user::UserByID {id}/>
</SidebarShell>
</ProtectedRoute>
},
Route::PermissionDenied => html! { <basic_pages::PermissionDenied/> },
Route::Diagnostics => html! {
<ProtectedRoute admin_page={true}>
<SidebarShell>
<utilities::Diagnostics/>
</SidebarShell>
</ProtectedRoute>
},
}
}
#[component(App)]
pub fn app() -> Html {
html! {
<BrowserRouter>
<Switch<Route> render={switch} />
</BrowserRouter>
}
}