From cdd1159b2e78c4a76fde0dd4a45374dddfe00f1b Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 30 Aug 2023 10:38:00 +0530 Subject: added conditional navbar links --- src/components/navbar/mod.rs | 5 ++- src/components/navbar/nav.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/components/navbar/nav.rs (limited to 'src') diff --git a/src/components/navbar/mod.rs b/src/components/navbar/mod.rs index 3aaeb72..7dbc08d 100644 --- a/src/components/navbar/mod.rs +++ b/src/components/navbar/mod.rs @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +mod nav; mod nav_link; use yew::prelude::*; @@ -33,9 +34,7 @@ pub fn navbar() -> Html { > - + } diff --git a/src/components/navbar/nav.rs b/src/components/navbar/nav.rs new file mode 100644 index 0000000..0cdc029 --- /dev/null +++ b/src/components/navbar/nav.rs @@ -0,0 +1,86 @@ +/* openbills-web - Web client for Libre Billing Software + * Copyright (C) 2023 Vidhu Kant Sharma + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +use yew::prelude::*; +use yew_router::prelude::*; + +use crate::app::Route; +use crate::components::navbar::nav_link::NavLink; + +#[derive(PartialEq)] +struct Link { + pub label: String, + pub to: Route, +} + +// shows different links based on the current route +#[function_component(Nav)] +pub fn nav() -> Html { + let current_route = use_route::().unwrap_or_default(); + + // fallback to this set of links + let default_links = Vec::from([ + Link { + label: String::from("Home"), + to: Route::Home, + }, + Link { + label: String::from("Manage"), + to: Route::ManageMenu, + }, + ]); + + let manage_links = Vec::from([ + Link { + label: String::from("Home"), + to: Route::Home, + }, + Link { + label: String::from("Clients"), + to: Route::ManageClients, + }, + Link { + label: String::from("Brands"), + to: Route::ManageBrands, + }, + Link { + label: String::from("Items"), + to: Route::ManageItems, + }, + Link { + label: String::from("Invoices"), + to: Route::ManageInvoices, + }, + ]); + + let links_html: Html = match current_route { + Route::ManageClients + | Route::ManageBrands + | Route::ManageItems + | Route::ManageInvoices => manage_links, + _ => default_links, + } + .iter() + .map(|link| html!()) + .collect(); + + html! { + + } +} -- cgit v1.2.3