From 6fdf7f01137f99c8b8b12dc0090214b5b89ae588 Mon Sep 17 00:00:00 2001 From: Lucas Vas Date: Wed, 14 Jan 2026 12:56:32 -0500 Subject: [PATCH] feat: add improvements to the date component --- src/components/date.rs | 179 +++++++++++++++++++++-------------------- src/pages/test_page.rs | 31 ++----- 2 files changed, 98 insertions(+), 112 deletions(-) diff --git a/src/components/date.rs b/src/components/date.rs index 6f91749..151e0e7 100644 --- a/src/components/date.rs +++ b/src/components/date.rs @@ -1,116 +1,119 @@ use crate::common::{DateInfo, DateRange, DateStatus}; -use leptos::either::{Either, EitherOf4}; use leptos::prelude::*; -/// # Date Component -/// -/// -/// Example usage - Single Date: -/// ``` -/// -/// ``` -/// Example usage - Date Range -/// ``` -/// -/// ``` fn render_dates(dates: DateRange) -> impl IntoView { - match dates { - DateRange::Single(date) => Either::Left(view! { -

{date}

- }), - DateRange::Range(start_date, end_date) => Either::Right(view! { -

{start_date} " - " {end_date}

- }), + let date_text = match dates { + DateRange::Single(date) => date, + DateRange::Range(start_date, end_date) => + format!("{} - {}", start_date, end_date), + }; + + view! { + {move || date_text.clone()} } } fn render_status(status: DateStatus) -> impl IntoView { - match status { - DateStatus::Upcoming => EitherOf4::A(view! { - - Upcoming - - }), - DateStatus::Open => EitherOf4::B(view! { - - Open - - }), - DateStatus::Deadline => EitherOf4::C(view! { - - Deadline - - }), - DateStatus::Closed => EitherOf4::D(view! { - - Closed - - }), + let status_text = match status { + DateStatus::Upcoming => "Upcoming", + DateStatus::Open => "Open", + DateStatus::Deadline => "Deadline", + DateStatus::Closed => "Closed", + }; + + view! { + + {move || status_text} + } } + +/// # Date Component +/// A single date, for use in a [`DateList`] component. +/// +/// Example usage: +/// ``` +/// let date_info = DateInfo { +/// title: "Example Title".to_string(), +/// date: DateRange::Single("January 1st, 1990".to_string()), +/// description: "A description of the date.".to_string(), +/// status: DateStatus::Upcoming +/// } +/// +/// view! { +/// +/// } +/// ``` #[component] -pub fn Date( +fn Date( /// Struct of title, date, and description - #[prop(into)] - important_dates: Vec, - /// The file path or URL of the icon displayed at the top of the button. - #[prop(into)] - icon: String, + #[prop(into)] info: Signal, ) -> impl IntoView { - important_dates - .into_iter() - .map(|info: DateInfo| { - view! { -
-
- icon -
+ view! { +
+ //
+ // icon + //

- {info.title} + {info.get().title}

- {render_dates(info.date)} + {move || render_dates(info.get().date)}

- {info.description} + {info.get().description}

- {render_status(info.status)} + {move || render_status(info.get().status)}
-
- } - }) - .collect_view() +
+ } +} + +///# Dates List Component +/// Displays a list of important dates in a column, with badges that draw attention to dates that +/// are more important. +/// +/// Example usage: +/// ``` +/// let dates = vec![ +/// DateInfo { +/// title: "Example Title".to_string(), +/// date: DateRange::Single("January 1st, 1990".to_string()), +/// description: "A description of the date.".to_string(), +/// status: DateStatus::Upcoming +/// } +/// ] +/// +/// view! { +/// +/// } +/// ``` +#[component] +pub fn DateList( + #[prop(into)] dates: Vec, +) -> impl IntoView { + view! { + {move || { + dates.iter() + .map(|info| { + view! { + + } + }).collect_view() + }} + } } diff --git a/src/pages/test_page.rs b/src/pages/test_page.rs index 800e6a7..2d16376 100644 --- a/src/pages/test_page.rs +++ b/src/pages/test_page.rs @@ -1,5 +1,5 @@ use crate::common::{DateInfo, DateRange, DateStatus}; -use crate::components::{DashboardButton, Date}; +use crate::components::{DashboardButton, DateList}; use leptos::prelude::*; #[component] @@ -36,50 +36,33 @@ pub fn TestPage() -> impl IntoView {
- - - -