barebones freetext field

This commit is contained in:
Robert Perce 2025-11-27 15:03:22 -06:00
parent 4e2fab67c5
commit 7b2ca09133
4 changed files with 37 additions and 2 deletions

View file

@ -0,0 +1,3 @@
alter table contacts
add column
text_body text;

View file

@ -0,0 +1,3 @@
alter table contacts
add column
text_body text;

View file

@ -93,6 +93,12 @@ mod get {
.fetch_all(pool)
.await?;
let text_body: Option<String> =
sqlx::query!("select text_body from contacts where id = $1", contact_id)
.fetch_one(pool)
.await?
.text_body;
Ok(layout.render(
Some(vec!["/static/contact.css", "/static/journal.css"]),
html! {
@ -149,6 +155,13 @@ mod get {
}
}
@if let Some(text_body) = text_body {
@if text_body.len() > 0 {
#text_body { (PreEscaped(markdown::to_html(&text_body))) }
}
}
(journal_section(pool, &entries).await?)
},
))
@ -190,6 +203,14 @@ mod get {
.manually_freshened_at
.clone()
.map_or("".to_string(), |m| m.to_rfc3339());
let text_body: String =
sqlx::query!("select text_body from contacts where id = $1", contact_id)
.fetch_one(pool)
.await?
.text_body
.unwrap_or(String::new());
Ok(layout.render(Some(vec!["/static/contact.css"]), html! {
form hx-ext="response-targets" {
div {
@ -240,6 +261,7 @@ mod get {
input type="button" value="Add" x-on:click="addresses.push({ label: new_label, value: new_address }); new_label = ''; new_address = ''";
}
}
textarea name="text_body" { (text_body) }
}
}))
}
@ -279,6 +301,7 @@ mod put {
manually_freshened_at: String,
address_label: Option<Vec<String>>,
address_value: Option<Vec<String>>,
text_body: String,
}
pub async fn contact(
@ -307,10 +330,17 @@ mod put {
)
};
let text_body = if payload.text_body.is_empty() {
None
} else {
Some(payload.text_body)
};
sqlx::query!(
"update contacts set (birthday, manually_freshened_at) = ($1, $2) where id = $3",
"update contacts set (birthday, manually_freshened_at, text_body) = ($1, $2, $3) where id = $4",
birthday,
manually_freshened_at,
text_body,
contact_id
)
.execute(pool)

View file

@ -9,7 +9,6 @@ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abb
body {
width: 100%;
min-height: 100vh;
font-size: 24px;
display: flex;
flex-direction: column;
align-items: center;