diff --git a/migrations/demo.db/0006_contact-text-body.sql b/migrations/demo.db/0006_contact-text-body.sql new file mode 100644 index 0000000..65eb200 --- /dev/null +++ b/migrations/demo.db/0006_contact-text-body.sql @@ -0,0 +1,3 @@ +alter table contacts + add column + text_body text; diff --git a/migrations/each_user/0006_contact-text-body.sql b/migrations/each_user/0006_contact-text-body.sql new file mode 100644 index 0000000..65eb200 --- /dev/null +++ b/migrations/each_user/0006_contact-text-body.sql @@ -0,0 +1,3 @@ +alter table contacts + add column + text_body text; diff --git a/src/web/contact.rs b/src/web/contact.rs index 7814e05..d996969 100644 --- a/src/web/contact.rs +++ b/src/web/contact.rs @@ -93,6 +93,12 @@ mod get { .fetch_all(pool) .await?; + let text_body: Option = + 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>, address_value: Option>, + 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) diff --git a/static/index.css b/static/index.css index 6293226..03bf9da 100644 --- a/static/index.css +++ b/static/index.css @@ -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;