feat: lives-with field
Some checks failed
/ integration-test--firefox (push) Failing after 3m6s

This commit is contained in:
Robert Perce 2026-01-24 11:13:27 -06:00
parent a0afb6dfd3
commit bacbfeb33c
3 changed files with 39 additions and 17 deletions

View file

@ -0,0 +1 @@
alter table contacts add column lives_with text not null default '';

View file

@ -11,6 +11,7 @@ pub struct Contact {
pub id: DbId, pub id: DbId,
pub birthday: Option<Birthday>, pub birthday: Option<Birthday>,
pub manually_freshened_at: Option<DateTime<Utc>>, pub manually_freshened_at: Option<DateTime<Utc>>,
pub lives_with: String,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -55,10 +56,13 @@ impl FromRow<'_, SqliteRow> for Contact {
.map(|d| d.to_utc()) .map(|d| d.to_utc())
}); });
let lives_with: String = row.try_get("lives_with")?;
Ok(Self { Ok(Self {
id, id,
birthday, birthday,
manually_freshened_at, manually_freshened_at,
lives_with,
}) })
} }
} }

View file

@ -74,12 +74,12 @@ mod get {
) -> Result<Markup, AppError> { ) -> Result<Markup, AppError> {
let pool = &state.db(&auth_session.user.unwrap()).pool; let pool = &state.db(&auth_session.user.unwrap()).pool;
let contact: HydratedContact = sqlx::query_as( let contact: HydratedContact = sqlx::query_as(
"select id, birthday, manually_freshened_at, ( "select *, (
select string_agg(name,'\x1c' order by sort) select string_agg(name,'\x1c' order by sort)
from names where contact_id = c.id from names where contact_id = c.id
) as names ) as names
from contacts c from contacts c
where c.id = $1", where c.id = $1",
) )
.bind(contact_id) .bind(contact_id)
.fetch_one(pool) .fetch_one(pool)
@ -156,6 +156,12 @@ mod get {
"(never)" "(never)"
} }
} }
@if contact.lives_with.len() > 0 {
label { "lives with" }
div { (contact.lives_with) }
}
@if addresses.len() == 1 { @if addresses.len() == 1 {
label { "address" } label { "address" }
#addresses { #addresses {
@ -207,16 +213,21 @@ mod get {
) -> Result<Markup, AppError> { ) -> Result<Markup, AppError> {
let pool = &state.db(&auth_session.user.unwrap()).pool; let pool = &state.db(&auth_session.user.unwrap()).pool;
let contact: HydratedContact = sqlx::query_as( let contact: HydratedContact = sqlx::query_as(
"select id, birthday, manually_freshened_at, ( "select *, (
select string_agg(name,'\x1c' order by sort) select string_agg(name,'\x1c' order by sort)
from names where contact_id = c.id from names where contact_id = c.id
) as names, ( ) as names, (
select jes.date from journal_entries jes select jes.date from journal_entries jes
join journal_mentions cms on cms.entry_id = jes.id join journal_mentions cms on cms.entry_id = jes.id
where cms.url = '/contact/'||c.id where cms.url = '/contact/'||c.id
order by jes.date desc limit 1 or cms.url in (
) as last_mention_date from contacts c select '/group/'||name
where c.id = $1", from groups
where contact_id = c.id
)
order by jes.date desc limit 1
) as last_mention_date from contacts c
where c.id = $1",
) )
.bind(contact_id) .bind(contact_id)
.fetch_one(pool) .fetch_one(pool)
@ -289,6 +300,10 @@ mod get {
span x-text="date.length ? date.split('T')[0] : '(never)'" {} span x-text="date.length ? date.split('T')[0] : '(never)'" {}
input type="button" value="Mark fresh now" x-on:click="date = new Date().toISOString()"; input type="button" value="Mark fresh now" x-on:click="date = new Date().toISOString()";
} }
label { "lives with" }
div {
input name="lives_with" value=(contact.lives_with);
}
label { "addresses" } label { "addresses" }
div x-data=(json!({ "addresses": addresses, "new_label": "", "new_address": "" })) { div x-data=(json!({ "addresses": addresses, "new_label": "", "new_address": "" })) {
template x-for="(address, index) in addresses" x-bind:key="index" { template x-for="(address, index) in addresses" x-bind:key="index" {
@ -361,6 +376,7 @@ mod put {
name: Option<Vec<String>>, name: Option<Vec<String>>,
birthday: String, birthday: String,
manually_freshened_at: String, manually_freshened_at: String,
lives_with: String,
address_label: Option<Vec<String>>, address_label: Option<Vec<String>>,
address_value: Option<Vec<String>>, address_value: Option<Vec<String>>,
group: Option<Vec<String>>, group: Option<Vec<String>>,
@ -400,9 +416,10 @@ mod put {
}; };
sqlx::query!( sqlx::query!(
"update contacts set (birthday, manually_freshened_at, text_body) = ($1, $2, $3) where id = $4", "update contacts set (birthday, manually_freshened_at, lives_with, text_body) = ($1, $2, $3, $4) where id = $5",
birthday, birthday,
manually_freshened_at, manually_freshened_at,
payload.lives_with,
text_body, text_body,
contact_id contact_id
) )