feat: inactive contacts hidden in sidebar
This commit is contained in:
parent
f75260c079
commit
b079001cc5
7 changed files with 123 additions and 58 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue