feat: simplify tab code slightly
This commit is contained in:
1 parent
b21887f82b
commit
b4f7ff6382
6 files changed
+59
-35
No files matched your search
+3
-2
@@ -1,4 +1,4 @@
|
||||
use crate::pages::{ProviderPortal, ScholarshipInfoPage, ProviderContactPage, LoanerShell, LoanerFallback, LoanerBorrowForm, LoanerReturnForm, AuthCallbackPage, ApplicantsPageFallback, AdminShell, AdminHomePage, AdminProviderPage, AdminScholarshipPage, StudentShell, StudentHomePage, StudentDemographicsPage, AdditionalPage, AdminUtilsPage};
|
||||
use crate::pages::{ProviderPortal, ScholarshipInfoPage, ProviderContactPage, LoanerShell, LoanerFallback, LoanerBorrowForm, LoanerReturnForm, AuthCallbackPage, ApplicantsPageFallback, AdminShell, AdminHomePage, AdminProviderPage, AdminScholarshipPage, StudentShell, StudentHomePage, StudentDemographicsPage, AdditionalPage, AdminUtilsPage, StudentAthleticsPage};
|
||||
use leptos::prelude::*;
|
||||
use leptos_meta::{MetaTags, Stylesheet, Title, provide_meta_context};
|
||||
use leptos_oidc::AuthSignal;
|
||||
@@ -124,7 +124,8 @@ fn StudentRoutes() -> impl MatchNestedRoutes + Clone {
|
||||
<Route path=path!("callback") view=AuthCallbackPage />
|
||||
<Route path=path!("home") view=StudentHomePage />
|
||||
<Route path=path!("demographics") view=StudentDemographicsPage />
|
||||
<Route path=path!("additional") view=AdditionalPage />
|
||||
<Route path=path!("additional") view=AdditionalPage/>
|
||||
<Route path=path!("additional/athletics") view=StudentAthleticsPage />
|
||||
</ParentRoute>
|
||||
}
|
||||
.into_inner()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use leptos::prelude::*;
|
||||
use leptos::logging::log;
|
||||
use leptos::prelude::*;
|
||||
use leptos_router::components::{Outlet, A};
|
||||
use leptos_router::hooks::use_location;
|
||||
use crate::common::{SubTabInfo, TabInfo};
|
||||
@@ -48,6 +49,7 @@ use crate::common::{SubTabInfo, TabInfo};
|
||||
/// ```
|
||||
#[component]
|
||||
pub fn TabSidebarList(
|
||||
#[prop(into)] base_path: Signal<String>,
|
||||
#[prop(into)] tabs: Signal<Vec<TabInfo>>,
|
||||
) -> impl IntoView {
|
||||
// Create a series of tabs based on a given list of names and paths.
|
||||
@@ -60,7 +62,7 @@ pub fn TabSidebarList(
|
||||
key=|info| info.text.clone()
|
||||
let(TabInfo { text, path, sub_paths })
|
||||
>
|
||||
<SidebarTab text=text path=path sub_paths=sub_paths />
|
||||
<SidebarTab base_path=base_path text=text path=path sub_paths=sub_paths />
|
||||
</For>
|
||||
</nav>
|
||||
|
||||
@@ -73,17 +75,22 @@ pub fn TabSidebarList(
|
||||
|
||||
#[component]
|
||||
fn SidebarTab(
|
||||
#[prop(into)] base_path: Signal<String>,
|
||||
#[prop(into)] text: Signal<String>,
|
||||
#[prop(into)] path: Signal<String>,
|
||||
#[prop(into)] sub_paths: Signal<Vec<SubTabInfo>>,
|
||||
) -> impl IntoView {
|
||||
let location = use_location();
|
||||
|
||||
let full_path = Memo::new(move |_| {
|
||||
format!("/{}/{}", base_path.get(), path.get())
|
||||
});
|
||||
|
||||
let selected = Memo::new(move |_| {
|
||||
let current_path = location.pathname.get();
|
||||
|
||||
// There's extra logic here as well, but for now this works.
|
||||
current_path.starts_with(&path.get())
|
||||
current_path.starts_with(&full_path.get())
|
||||
});
|
||||
|
||||
view! {
|
||||
@@ -109,7 +116,7 @@ fn SidebarTab(
|
||||
key=|info| info.text.clone()
|
||||
let(SubTabInfo { text, path })
|
||||
>
|
||||
<SidebarSubTab text=text path=path visible=selected />
|
||||
<SidebarSubTab parent_path=full_path text=text path=path />
|
||||
</For>
|
||||
</div>
|
||||
</div>
|
||||
@@ -119,22 +126,17 @@ fn SidebarTab(
|
||||
|
||||
#[component]
|
||||
fn SidebarSubTab(
|
||||
#[prop(into)] parent_path: Signal<String>,
|
||||
#[prop(into)] text: Signal<String>,
|
||||
#[prop(into)] path: Signal<String>,
|
||||
#[prop(into)] visible: Signal<bool>,
|
||||
) -> impl IntoView {
|
||||
let selected = Memo::new(move |_| {
|
||||
visible.get()
|
||||
let full_path = Memo::new(move |_| {
|
||||
format!("{}/{}", parent_path.get(), path.get())
|
||||
});
|
||||
|
||||
view! {
|
||||
<A href=move || path.get()>
|
||||
<div
|
||||
class="p-3 pl-10 transition-all"
|
||||
class=(["font-bold"], move || selected.get())
|
||||
>
|
||||
{text}
|
||||
</div>
|
||||
<A href=move || full_path.get() {..} class="block p-3 pl-10 transition-all aria-[current]:font-bold">
|
||||
{text}
|
||||
</A>
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,15 @@ pub fn AdminShell() -> impl IntoView {
|
||||
<AdminLoginContext>
|
||||
<Banner title="R15 Scholarships Admin" logo="/PHS_Stacked_Acronym.png" />
|
||||
// We'll put the tabs here.
|
||||
<TabSidebarList tabs=vec![
|
||||
TabInfo::new("Home", "/admin/home", None),
|
||||
TabInfo::new("Providers", "/admin/providers", None),
|
||||
TabInfo::new("Scholarships", "/admin/scholarships", None),
|
||||
TabInfo::new("Utilities", "/admin/utilities", None),
|
||||
] />
|
||||
<TabSidebarList
|
||||
base_path="admin"
|
||||
tabs=vec![
|
||||
TabInfo::new("Home", "home", None),
|
||||
TabInfo::new("Providers", "providers", None),
|
||||
TabInfo::new("Scholarships", "scholarships", None),
|
||||
TabInfo::new("Utilities", "utilities", None),
|
||||
]
|
||||
/>
|
||||
</AdminLoginContext>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
use leptos::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn StudentAthleticsPage() -> impl IntoView {
|
||||
view! {
|
||||
<div class="flex flex-1 flex-col gap-4 items-center m-4">
|
||||
<div class="font-bold text-3xl">"Student Athletics Form"</div>
|
||||
<div class="text-lg">
|
||||
"This is just a placeholder for now. This will display the athletics form."
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ mod shell;
|
||||
mod home_page;
|
||||
mod demographics_page;
|
||||
mod additional_page;
|
||||
mod athletics_page;
|
||||
|
||||
pub use shell::*;
|
||||
pub use home_page::*;
|
||||
pub use demographics_page::*;
|
||||
pub use additional_page::*;
|
||||
pub use athletics_page::*;
|
||||
+16
-13
@@ -13,19 +13,22 @@ pub fn StudentShell() -> impl IntoView {
|
||||
<Banner title="R15 Student Scholarship Application" logo="/PHS_Stacked_Acronym.png" />
|
||||
<AuthLoaded fallback=Loading>
|
||||
<Authenticated unauthenticated=UnauthenticatedPage>
|
||||
<TabSidebarList tabs=vec![
|
||||
TabInfo::new("Home", "/students/home", None),
|
||||
TabInfo::new("Demographics", "/students/demographics",
|
||||
Some(vec![
|
||||
SubTabInfo::new("Testing", "/students/testing"),
|
||||
SubTabInfo::new("Testing Again!", "/students/testing/again")
|
||||
])),
|
||||
TabInfo::new("Additional Info", "/students/additional",
|
||||
Some(vec![
|
||||
SubTabInfo::new("Testing", "/students/testing"),
|
||||
SubTabInfo::new("Testing Again!", "/students/testing/again")
|
||||
])),
|
||||
] />
|
||||
<TabSidebarList
|
||||
base_path="students"
|
||||
tabs=vec![
|
||||
TabInfo::new("Home", "home", None),
|
||||
TabInfo::new("Demographics", "demographics", None),
|
||||
TabInfo::new("Additional Info", "additional",
|
||||
Some(vec![
|
||||
SubTabInfo::new("Academics", "academics"),
|
||||
SubTabInfo::new("Athletics", "athletics"),
|
||||
SubTabInfo::new("Work Experience", "work-experience"),
|
||||
SubTabInfo::new("Extracurriculars", "extracurriculars"),
|
||||
SubTabInfo::new("University Info", "university"),
|
||||
SubTabInfo::new("Parent Info", "parent-info")
|
||||
])),
|
||||
]
|
||||
/>
|
||||
</Authenticated>
|
||||
</AuthLoaded>
|
||||
</StudentLoginContext>
|
||||
|
||||
Reference in new issue
Block a user