feat: show birthdays until a week out
This commit is contained in:
parent
4c710dcd20
commit
18c1e41693
1 changed files with 30 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use cache_bust::asset;
|
use cache_bust::asset;
|
||||||
use jiff::{Timestamp, Unit, Zoned, civil, tz::TimeZone};
|
use jiff::{Timestamp, ToSpan, Unit, Zoned, civil, tz::TimeZone};
|
||||||
use maud::{Markup, html};
|
use maud::{Markup, html};
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
|
||||||
|
|
@ -53,13 +53,40 @@ fn birthdays_section(
|
||||||
prev_birthdays: &Vec<KnownBirthdayContact>,
|
prev_birthdays: &Vec<KnownBirthdayContact>,
|
||||||
upcoming_birthdays: &Vec<KnownBirthdayContact>,
|
upcoming_birthdays: &Vec<KnownBirthdayContact>,
|
||||||
) -> Result<Markup, AppError> {
|
) -> Result<Markup, AppError> {
|
||||||
|
let now = Timestamp::now().to_zoned(TimeZone::UTC);
|
||||||
|
let in_a_week = upcoming_birthdays
|
||||||
|
.iter()
|
||||||
|
.position(|b| {
|
||||||
|
now.until(&b.next_birthday.to_zoned(TimeZone::UTC).unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.compare((&1_i32.week(), &now))
|
||||||
|
.unwrap()
|
||||||
|
!= std::cmp::Ordering::Less
|
||||||
|
})
|
||||||
|
.unwrap_or(upcoming_birthdays.len());
|
||||||
|
let upcoming = &upcoming_birthdays
|
||||||
|
[0..std::cmp::min(std::cmp::max(3, in_a_week + 1), upcoming_birthdays.len())];
|
||||||
|
|
||||||
|
let a_week_ago = prev_birthdays
|
||||||
|
.iter()
|
||||||
|
.position(|b| {
|
||||||
|
now.since(&b.prev_birthday.to_zoned(TimeZone::UTC).unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.compare((&1_i32.week(), &now))
|
||||||
|
.unwrap()
|
||||||
|
!= std::cmp::Ordering::Less
|
||||||
|
})
|
||||||
|
.unwrap_or(upcoming_birthdays.len());
|
||||||
|
let recent =
|
||||||
|
&prev_birthdays[0..std::cmp::min(std::cmp::max(3, a_week_ago + 1), prev_birthdays.len())];
|
||||||
|
|
||||||
Ok(html! {
|
Ok(html! {
|
||||||
div id="birthdays" {
|
div id="birthdays" {
|
||||||
h2 { "Birthdays" }
|
h2 { "Birthdays" }
|
||||||
#birthday-sections {
|
#birthday-sections {
|
||||||
.datelist #upcoming {
|
.datelist #upcoming {
|
||||||
h3 { "upcoming" }
|
h3 { "upcoming" }
|
||||||
@for contact in &upcoming_birthdays[0..std::cmp::min(3, upcoming_birthdays.len())] {
|
@for contact in upcoming {
|
||||||
a href=(format!("/contact/{}", contact.contact_id)) {
|
a href=(format!("/contact/{}", contact.contact_id)) {
|
||||||
(contact.display)
|
(contact.display)
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +97,7 @@ fn birthdays_section(
|
||||||
}
|
}
|
||||||
.datelist #recent {
|
.datelist #recent {
|
||||||
h3 { "recent" }
|
h3 { "recent" }
|
||||||
@for contact in &prev_birthdays[0..std::cmp::min(3, prev_birthdays.len())] {
|
@for contact in recent {
|
||||||
a href=(format!("/contact/{}", contact.contact_id)) {
|
a href=(format!("/contact/{}", contact.contact_id)) {
|
||||||
(contact.display)
|
(contact.display)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue