2023-09-22 21:26:13 +02:00
|
|
|
use crate::locales::init_locales;
|
2023-09-18 13:10:59 +02:00
|
|
|
use crate::pages::home_page::HomePage;
|
|
|
|
|
use crate::pages::settings::Settings;
|
2026-10-12 07:51:29 +02:00
|
|
|
use leptos::prelude::*;
|
2023-08-18 12:22:23 +02:00
|
|
|
use leptos_meta::*;
|
2026-10-12 07:51:29 +02:00
|
|
|
use leptos_router::components::{Route, Router, Routes};
|
|
|
|
|
use leptos_router::hooks::use_location;
|
|
|
|
|
use leptos_router::path;
|
2023-09-22 21:26:13 +02:00
|
|
|
use crate::components::admin_portal::AdminPortal;
|
|
|
|
|
use crate::components::header::Header;
|
2023-10-09 17:33:20 +02:00
|
|
|
use crate::components::user_menu::MenuOpener;
|
2024-02-14 16:46:31 +01:00
|
|
|
use crate::pages::all_reservations::Bookings;
|
2024-02-22 21:54:00 +01:00
|
|
|
use crate::pages::appearance_settings::Appearance;
|
2024-02-15 16:46:57 +01:00
|
|
|
use crate::pages::customers::Customers;
|
2023-09-22 21:26:13 +02:00
|
|
|
use crate::pages::login::Login;
|
2024-02-10 19:52:20 +01:00
|
|
|
use crate::pages::mail_settings::MailSettings;
|
2023-09-22 21:26:13 +02:00
|
|
|
use crate::pages::public::Public;
|
2023-08-18 12:22:23 +02:00
|
|
|
|
2026-10-12 07:51:29 +02:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
2023-10-09 17:33:20 +02:00
|
|
|
pub struct MenuHelper {
|
2026-10-12 07:51:29 +02:00
|
|
|
opened: RwSignal<Option<MenuOpener>>
|
2023-10-09 17:33:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MenuHelper {
|
|
|
|
|
pub fn new() -> Self {
|
2026-10-12 07:51:29 +02:00
|
|
|
let opened = RwSignal::new(None);
|
2023-10-09 17:33:20 +02:00
|
|
|
Self {
|
|
|
|
|
opened
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_opened(&self, opened: MenuOpener) {
|
2026-10-12 07:51:29 +02:00
|
|
|
self.opened.set(Some(opened));
|
2023-10-09 17:33:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn close(&self) {
|
2026-10-12 07:51:29 +02:00
|
|
|
if let Some(opened) = self.opened.get_untracked() {
|
|
|
|
|
opened.close();
|
|
|
|
|
}
|
2023-10-09 17:33:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn reset(&self) {
|
2026-10-12 07:51:29 +02:00
|
|
|
self.opened.set(None);
|
2023-10-09 17:33:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-21 18:15:25 +01:00
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
|
pub struct DialogHelper {
|
|
|
|
|
opened: RwSignal<bool>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl DialogHelper {
|
|
|
|
|
pub fn new() -> Self {
|
2026-10-12 07:51:29 +02:00
|
|
|
let opened = RwSignal::new(false);
|
2023-11-21 18:15:25 +01:00
|
|
|
Self {
|
|
|
|
|
opened
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_opened(&self, opened: bool) {
|
|
|
|
|
self.opened.set(opened);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn is_open(&self) -> bool {
|
|
|
|
|
self.opened.get()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 18:10:29 +02:00
|
|
|
#[component]
|
|
|
|
|
fn app_footer() -> impl IntoView {
|
|
|
|
|
let loc = use_location();
|
|
|
|
|
|
|
|
|
|
view! {
|
|
|
|
|
<footer class="content-footer footer bg-footer-theme" style={move || if loc.pathname.get().starts_with("/admin") {"display: none;"} else {"display: block;"}}>
|
2026-10-12 07:51:29 +02:00
|
|
|
<div class="mb-2 mb-md-0" style="text-align: center">
|
2024-09-04 18:10:29 +02:00
|
|
|
<a href="https://rezervovator.cz" target="_blank"><img src="/rezervovator_l.svg" width="110"/></a> {format!(" v {}", env!("CARGO_PKG_VERSION"))}
|
|
|
|
|
</div>
|
|
|
|
|
</footer>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 12:22:23 +02:00
|
|
|
#[component]
|
2023-09-15 13:55:01 +02:00
|
|
|
pub fn App() -> impl IntoView {
|
2023-08-18 12:22:23 +02:00
|
|
|
// Provides context that manages stylesheets, titles, meta tags, etc.
|
2023-09-15 13:55:01 +02:00
|
|
|
provide_meta_context();
|
2023-09-18 13:10:59 +02:00
|
|
|
init_locales();
|
2024-02-10 19:52:20 +01:00
|
|
|
provide_context(MenuHelper::new()); // Only one menu can be opened
|
|
|
|
|
provide_context(MenuOpener::new()); // Drawer opener
|
|
|
|
|
provide_context(DialogHelper::new()); // Gray dialog background
|
2023-08-18 12:22:23 +02:00
|
|
|
|
|
|
|
|
view! {
|
2023-09-22 21:26:13 +02:00
|
|
|
<Header/>
|
2023-08-18 12:22:23 +02:00
|
|
|
|
|
|
|
|
<Router>
|
|
|
|
|
<main>
|
2026-10-12 07:51:29 +02:00
|
|
|
<Routes fallback=|| "Page not found.">
|
|
|
|
|
<Route path=path!("") view=|| view! { <Public/> }/>
|
|
|
|
|
<Route path=path!("login") view=|| view! { <Login/> }/>
|
|
|
|
|
<Route path=path!("admin") view=|| view! {
|
2023-09-22 21:26:13 +02:00
|
|
|
<AdminPortal>
|
|
|
|
|
<HomePage/>
|
|
|
|
|
</AdminPortal>
|
|
|
|
|
}/>
|
2026-10-12 07:51:29 +02:00
|
|
|
<Route path=path!("admin/settings") view=|| view! {
|
2023-09-22 21:26:13 +02:00
|
|
|
<AdminPortal>
|
|
|
|
|
<Settings/>
|
|
|
|
|
</AdminPortal>
|
|
|
|
|
}/>
|
2026-10-12 07:51:29 +02:00
|
|
|
<Route path=path!("admin/mail_settings") view=|| view! {
|
2024-02-10 19:52:20 +01:00
|
|
|
<AdminPortal>
|
|
|
|
|
<MailSettings/>
|
|
|
|
|
</AdminPortal>
|
|
|
|
|
}/>
|
2026-10-12 07:51:29 +02:00
|
|
|
<Route path=path!("admin/bookings") view=|| view! {
|
2024-02-14 16:46:31 +01:00
|
|
|
<AdminPortal>
|
|
|
|
|
<Bookings/>
|
|
|
|
|
</AdminPortal>
|
|
|
|
|
}/>
|
2026-10-12 07:51:29 +02:00
|
|
|
<Route path=path!("admin/customers") view=|| view! {
|
2024-02-15 16:46:57 +01:00
|
|
|
<AdminPortal>
|
|
|
|
|
<Customers/>
|
|
|
|
|
</AdminPortal>
|
|
|
|
|
}/>
|
2026-10-12 07:51:29 +02:00
|
|
|
<Route path=path!("admin/appearance") view=|| view! {
|
2024-02-22 21:54:00 +01:00
|
|
|
<AdminPortal>
|
|
|
|
|
<Appearance/>
|
|
|
|
|
</AdminPortal>
|
|
|
|
|
}/>
|
2023-08-18 12:22:23 +02:00
|
|
|
</Routes>
|
|
|
|
|
</main>
|
2024-09-04 18:10:29 +02:00
|
|
|
<AppFooter/>
|
2023-08-18 12:22:23 +02:00
|
|
|
</Router>
|
|
|
|
|
}
|
|
|
|
|
}
|