diff --git a/src-tauri/.sqlx/query-2ae6a2e4b05d43cfba5908f37236ac4bb4e6952010729a181f3501c37dbba429.json b/src-tauri/.sqlx/query-2ae6a2e4b05d43cfba5908f37236ac4bb4e6952010729a181f3501c37dbba429.json new file mode 100644 index 0000000..b5a9de0 --- /dev/null +++ b/src-tauri/.sqlx/query-2ae6a2e4b05d43cfba5908f37236ac4bb4e6952010729a181f3501c37dbba429.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "\n INSERT INTO highlight ( content, kind ) \n VALUES ( $1, $2 )\n ", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "2ae6a2e4b05d43cfba5908f37236ac4bb4e6952010729a181f3501c37dbba429" +} diff --git a/src-tauri/.sqlx/query-32a38839f74743cc70bc2671573c05ede2fb7100f4a3aa8d38d4603bdb417b9b.json b/src-tauri/.sqlx/query-32a38839f74743cc70bc2671573c05ede2fb7100f4a3aa8d38d4603bdb417b9b.json deleted file mode 100644 index 85d5641..0000000 --- a/src-tauri/.sqlx/query-32a38839f74743cc70bc2671573c05ede2fb7100f4a3aa8d38d4603bdb417b9b.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "db_name": "SQLite", - "query": "\n INSERT INTO highlight ( content, kind ) \n VALUES ( $1, $2 )\n RETURNING id as \"id: i32\", content, kind as \"kind: Kind\", created_at, updated_at\n ", - "describe": { - "columns": [ - { - "name": "id: i32", - "ordinal": 0, - "type_info": "Int64" - }, - { - "name": "content", - "ordinal": 1, - "type_info": "Text" - }, - { - "name": "kind: Kind", - "ordinal": 2, - "type_info": "Text" - }, - { - "name": "created_at", - "ordinal": 3, - "type_info": "Datetime" - }, - { - "name": "updated_at", - "ordinal": 4, - "type_info": "Datetime" - } - ], - "parameters": { - "Right": 2 - }, - "nullable": [ - false, - false, - false, - false, - true - ] - }, - "hash": "32a38839f74743cc70bc2671573c05ede2fb7100f4a3aa8d38d4603bdb417b9b" -} diff --git a/src-tauri/src/highlight.rs b/src-tauri/src/highlight.rs index e3695b2..e000001 100644 --- a/src-tauri/src/highlight.rs +++ b/src-tauri/src/highlight.rs @@ -1,6 +1,8 @@ use serde::{Deserialize, Serialize}; +use tap::Tap; use tauri::{async_runtime::block_on, State}; use time::OffsetDateTime; +use tracing::debug; use crate::db::DbWrapper; @@ -33,32 +35,25 @@ pub fn record_highlight( state: State<'_, DbWrapper>, req: CreateHighlightRequest, ) -> GroupedHighlight { - let future = sqlx::query_as!( - Highlight, + let future = sqlx::query!( r#" INSERT INTO highlight ( content, kind ) VALUES ( $1, $2 ) - RETURNING id as "id: i32", content, kind as "kind: Kind", created_at, updated_at "#, req.content, req.kind ) - .fetch_one(&state.pool); - let highlight = block_on(future).expect("error while saving highlight to database"); - - let todays_highlight = get_todays_highlight(state); - return if let Some(mut grouped_highlight) = todays_highlight { - grouped_highlight.add_highlight(highlight); - grouped_highlight - } else { - GroupedHighlight::new(highlight) - }; + .execute(&state.pool); + block_on(future).expect("error while saving highlight to database"); + get_todays_highlight(state) + .expect("error while fetching saved highlight") + .tap(|gh| debug!("returning saved highlight in today's grouped highlight\n{gh:#?}")) } #[derive(Debug, Serialize, Deserialize, specta::Type)] pub struct GroupedHighlight { - pub best: Option, - pub worst: Option, + pub best: Vec, + pub worst: Vec, #[serde(with = "time::serde::timestamp::milliseconds")] pub date: OffsetDateTime, } @@ -68,13 +63,13 @@ impl GroupedHighlight { let created_at = highlight.created_at.clone(); match highlight.kind { Kind::Best => Self { - best: Some(highlight), - worst: None, + best: vec![highlight], + worst: vec![], date: created_at, }, Kind::Worst => Self { - best: None, - worst: Some(highlight), + best: vec![], + worst: vec![highlight], date: created_at, }, } @@ -82,8 +77,8 @@ impl GroupedHighlight { pub fn add_highlight(&mut self, highlight: Highlight) { match highlight.kind { - Kind::Best => self.best = Some(highlight), - Kind::Worst => self.worst = Some(highlight), + Kind::Best => self.best.push(highlight), + Kind::Worst => self.worst.push(highlight), }; } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 58982a2..f26b0ef 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -22,10 +22,9 @@ fn main() { specta_builder.into_plugin() }; - let subscriber = tracing_subscriber::FmtSubscriber::builder() + tracing_subscriber::FmtSubscriber::builder() .with_max_level(Level::INFO) - .finish(); - tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); + .init(); tauri::Builder::default() .setup(|app| { diff --git a/src/bindings.ts b/src/bindings.ts index 13bf961..20495bc 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -4,7 +4,7 @@ async recordHighlight(req: CreateHighlightRequest) : Promise { return await TAURI_INVOKE("plugin:tauri-specta|record_highlight", { req }); }, -async getTodaysHighlight() : Promise<{ best: Highlight | null; worst: Highlight | null; date: string } | null> { +async getTodaysHighlight() : Promise<{ best: Highlight[]; worst: Highlight[]; date: string } | null> { return await TAURI_INVOKE("plugin:tauri-specta|get_todays_highlight"); }, async listHighlights() : Promise { @@ -17,7 +17,7 @@ return await TAURI_INVOKE("plugin:tauri-specta|list_highlights"); /** user-defined types **/ export type CreateHighlightRequest = { content: string; kind: Kind } -export type GroupedHighlight = { best: Highlight | null; worst: Highlight | null; date: string } +export type GroupedHighlight = { best: Highlight[]; worst: Highlight[]; date: string } export type Highlight = { id: number; content: string; kind: Kind; created_at: string; updated_at: string | null } export type Kind = "BEST" | "WORST" diff --git a/src/lib/layouts/ViewMain.svelte b/src/lib/layouts/ViewMain.svelte index adbfc87..839454e 100644 --- a/src/lib/layouts/ViewMain.svelte +++ b/src/lib/layouts/ViewMain.svelte @@ -10,5 +10,6 @@ gap: 8px; margin-left: 8px; margin-right: 8px; + padding-bottom: 8px; } diff --git a/src/view/List.svelte b/src/view/List.svelte index 0cdcc48..982df8e 100644 --- a/src/view/List.svelte +++ b/src/view/List.svelte @@ -22,24 +22,28 @@ {dayjs(highlight.date).fromNow()} -
-
-
    -
  • {highlight.best?.content}
  • -
-
-
-
    -
  • {highlight.worst?.content}
  • -
-
-
+
    + {#each highlight.best as best, index} +
  • + + {best?.content} +
  • + {/each} + {#each highlight.worst as worst} +
  • + + {worst?.content} +
  • + {/each} +
{:else}

No highlights to list yet!

@@ -64,35 +68,38 @@ } & .highlight-container { - display: flex; - flex-direction: column; - justify-content: center; - width: 100%; - - & div[class^='highlight-'] { - font-size: small; + font-size: small; + margin: 0; + padding-left: 0; - & ul { - list-style-type: none; - margin: 8px; - padding-left: 4px; + & li { + align-items: center; + display: flex; + gap: 4px; - & li { - align-items: center; - display: flex; - gap: 4px; - } + & * { + margin: 4px; } } - & .highlight-best { + & li:first-of-type { border-top-right-radius: 8px; - color: var(--very-dark); } - & .highlight-worst { + & li:last-of-type { border-bottom-left-radius: 8px; border-bottom-right-radius: 8px; + } + + & li[data-last='true'] { + border-bottom: 2px solid var(--highlight); + } + + & .highlight-best { + color: var(--very-dark); + } + + & .highlight-worst { color: var(--light); } } diff --git a/src/view/Record.svelte b/src/view/Record.svelte index 9788b87..3faea0d 100644 --- a/src/view/Record.svelte +++ b/src/view/Record.svelte @@ -102,12 +102,14 @@ kind === HighlightKind.WORST ? $todaysHighlight.worst : $todaysHighlight.best}
    -
  • - {highlights?.content} -
  • + {#each highlights as highlight} +
  • + {highlight?.content} +
  • + {/each}
{/if} @@ -210,10 +212,19 @@ padding-left: 24px; & li { - border-radius: 8px; padding: 8px; } + & li:first-of-type { + border-top-left-radius: 8px; + border-top-right-radius: 8px; + } + + & li:last-of-type { + border-bottom-left-radius: 8px; + border-bottom-right-radius: 8px; + } + & li::marker { color: var(--very-dark); }