feat: inactive contacts hidden in sidebar

This commit is contained in:
Robert Perce 2026-04-03 16:03:16 -05:00
parent f75260c079
commit b079001cc5
7 changed files with 123 additions and 58 deletions

View file

@ -223,7 +223,9 @@ mod get {
let mfresh_str = contact
.manually_freshened_at
.clone()
.map_or("".to_string(), |m| m.to_string());
.map_or("".to_string(), |m| {
m.to_zoned(TimeZone::UTC).date().to_string()
});
let text_body: String =
sqlx::query!("select text_body from contacts where id = $1", contact_id)
@ -278,10 +280,20 @@ mod get {
span .hint { code { "(yyyy|--)mmdd" } " or free text" }
}
label { "freshened" }
div x-data=(json!({ "date": mfresh_str })) {
input type="hidden" name="manually_freshened_at" x-model="date";
span x-text="date.length ? date.split('T')[0] : '(never)'" {}
input type="button" value="Mark fresh now" x-on:click="date = new Date().toISOString()";
div x-data=(json!({ "date": mfresh_str, "stamp": "" })) x-init="today = () => (new Date().toISOString().split('T')[0])" {
input
type="hidden"
name="manually_freshened_at"
x-model="stamp";
input
type="date"
name="manually_freshened_on"
x-model="date"
x-bind:max="today()"
x-on:input="stamp = new Date(date).toISOString()";
input type="button" value="Mark fresh now" x-on:click="date = today(); stamp = new Date().toISOString()";
span .hint x-text="`max ${today()}`";
}
label { "phone" }
#phone_numbers x-data=(json!({ "phones": phone_numbers, "new_label": "", "new_number": "" })) {

View file

@ -25,6 +25,7 @@ struct ContactLink {
#[derive(Debug)]
pub struct Layout {
contact_links: Vec<ContactLink>,
inactive_contact_links: Vec<ContactLink>,
user: User,
}
@ -48,6 +49,20 @@ impl FromRequestParts<AppState> for Layout {
from contacts c
left join names n on c.id = n.contact_id
where n.sort is null or n.sort = 0
and c.active = true
order by name asc",
)
.fetch_all(&state.db(&user).pool)
.await?;
let inactive_contact_links = sqlx::query_as!(
ContactLink,
"select c.id as contact_id,
coalesce(n.name, '(unnamed)') as name
from contacts c
left join names n on c.id = n.contact_id
where n.sort is null or n.sort = 0
and c.active = false
order by name asc",
)
.fetch_all(&state.db(&user).pool)
@ -55,13 +70,19 @@ impl FromRequestParts<AppState> for Layout {
Ok(Layout {
contact_links,
inactive_contact_links,
user,
})
}
}
impl Layout {
pub fn render(&self, title: impl AsRef<str>, css: Option<Vec<&str>>, content: Markup) -> Markup {
pub fn render(
&self,
title: impl AsRef<str>,
css: Option<Vec<&str>>,
content: Markup,
) -> Markup {
html! {
(DOCTYPE)
html {
@ -101,6 +122,23 @@ impl Layout {
}
}
}
@if !self.inactive_contact_links.is_empty() {
li .inactive {
details {
summary { "Inactive contacts" }
ul {
@for link in &self.inactive_contact_links {
li {
a href=(format!("/contact/{}", link.contact_id)) {
(link.name)
}
}
}
}
}
}
}
}
}
main {