From eb51bdbfef8c2aacf0fdfde279a40de7f74c8d86 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Mon, 18 Mar 2024 21:27:24 -0400 Subject: clean up, add better error handling --- fe/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fe/src') diff --git a/fe/src/utils.ts b/fe/src/utils.ts index 9fddf41..41c733d 100644 --- a/fe/src/utils.ts +++ b/fe/src/utils.ts @@ -10,5 +10,5 @@ export function processFormInput(form: HTMLFormElement) { export function apiURL (path: string): string { const baseUrl = import.meta.env?.VITE_API_BASE_URL ?? "http://localhost:8080/api/v1"; - return `${baseUrl}${path}` + return `${baseUrl}/${path}` } -- cgit v1.1 From fd6f6f169f9ff9a1247228fb34dc9654a9584915 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Thu, 21 Mar 2024 11:23:42 -0400 Subject: fix bugs, redo layout, reorg. --- fe/src/App.svelte | 2 +- fe/src/app.css | 53 +++++--------- fe/src/lib/Card.svelte | 5 +- fe/src/lib/Column.svelte | 8 ++- fe/src/lib/DataView.svelte | 8 +-- fe/src/lib/Layout.svelte | 51 +++++++++++--- fe/src/lib/LoginForm.svelte | 86 ----------------------- fe/src/lib/PreferencesForm.svelte | 119 -------------------------------- fe/src/lib/Table.svelte | 10 ++- fe/src/lib/forms/AddForm.svelte | 25 ++----- fe/src/lib/forms/LoginForm.svelte | 86 +++++++++++++++++++++++ fe/src/lib/forms/PreferencesForm.svelte | 119 ++++++++++++++++++++++++++++++++ fe/src/lib/forms/index.ts | 10 +++ fe/src/types.ts | 2 +- 14 files changed, 297 insertions(+), 287 deletions(-) delete mode 100644 fe/src/lib/LoginForm.svelte delete mode 100644 fe/src/lib/PreferencesForm.svelte create mode 100644 fe/src/lib/forms/LoginForm.svelte create mode 100644 fe/src/lib/forms/PreferencesForm.svelte create mode 100644 fe/src/lib/forms/index.ts (limited to 'fe/src') diff --git a/fe/src/App.svelte b/fe/src/App.svelte index 25d53dc..11eb217 100644 --- a/fe/src/App.svelte +++ b/fe/src/App.svelte @@ -1,6 +1,6 @@ diff --git a/fe/src/app.css b/fe/src/app.css index c24c713..be7d15c 100644 --- a/fe/src/app.css +++ b/fe/src/app.css @@ -5,48 +5,34 @@ color-scheme: light dark; color: rgba(255, 255, 255, 0.87); - background-color: #242424; + background-color: var(--background); + width: 100vw; font-synthesis: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; - --submit: #28a745; + --background: #242424; } -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} +@media (min-width: 916px) { + :root { + width: unset; + } -a:hover { - color: #535bf2; + #content div.column:first-child { + flex-direction: row; + height: 300px; + } } body { margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; + padding: 0 2em 2em; } -h1 { - font-size: 3.2em; - line-height: 1.1; -} -.card { - padding: 2em; -} - -#app { - flex-grow: 2; - max-width: 1280px; - margin: 0 auto; -} button { border-radius: 8px; @@ -56,6 +42,7 @@ button { font-weight: 500; font-family: inherit; background-color: #1a1a1a; + color: inherit; cursor: pointer; transition: border-color 0.25s; } @@ -64,10 +51,6 @@ button:hover { border-color: #646cff; } -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} @media (prefers-color-scheme: light) { :root { @@ -84,12 +67,6 @@ button:focus-visible { } } -@media (prefers-color-scheme: dark) { - :root { - color: #000; - } -} - .form { display: flex; flex-direction: column; @@ -118,3 +95,7 @@ button:focus-visible { background: var(--submit); color: #fff; } + +dialog { + top: 8em; +} diff --git a/fe/src/lib/Card.svelte b/fe/src/lib/Card.svelte index cd1e02c..0f29279 100644 --- a/fe/src/lib/Card.svelte +++ b/fe/src/lib/Card.svelte @@ -11,13 +11,12 @@ diff --git a/fe/src/lib/Column.svelte b/fe/src/lib/Column.svelte index f036073..6902edf 100644 --- a/fe/src/lib/Column.svelte +++ b/fe/src/lib/Column.svelte @@ -7,7 +7,13 @@ display: flex; flex-direction: column; height: 100%; - gap: var(--gap, 32px); + gap: var(--gap, 2em); width: var(--width, initial); } + + @media (min-width: 916px) { + .column { + flex-direction: column; + } + } \ No newline at end of file diff --git a/fe/src/lib/DataView.svelte b/fe/src/lib/DataView.svelte index ffc2fe8..1496239 100644 --- a/fe/src/lib/DataView.svelte +++ b/fe/src/lib/DataView.svelte @@ -205,12 +205,11 @@ }); - - - + + - + @@ -225,4 +224,3 @@ {/await} - diff --git a/fe/src/lib/Layout.svelte b/fe/src/lib/Layout.svelte index 2728dd3..26630d2 100644 --- a/fe/src/lib/Layout.svelte +++ b/fe/src/lib/Layout.svelte @@ -1,6 +1,6 @@ - - -
-
- - -
-
- - -
- {#if error} -

{error}

- {/if} - -
-
diff --git a/fe/src/lib/PreferencesForm.svelte b/fe/src/lib/PreferencesForm.svelte deleted file mode 100644 index 74b8a63..0000000 --- a/fe/src/lib/PreferencesForm.svelte +++ /dev/null @@ -1,119 +0,0 @@ - - - -

User Preferences

-
-
- - -
-
- - -
- - -
-
- - diff --git a/fe/src/lib/Table.svelte b/fe/src/lib/Table.svelte index 621157e..3ce3331 100644 --- a/fe/src/lib/Table.svelte +++ b/fe/src/lib/Table.svelte @@ -7,7 +7,7 @@ export let sortBy: string = 'date'; - type SortComparator = (a, b) => number + type SortComparator = (a:any , b:any) => number function getDataKeys(data: any[]): string[] { if (!data || data.length === 0) return []; @@ -20,7 +20,7 @@ return Object.entries(row).filter((r) => !omit.includes(r[0])); } - function sort(arr: Array>, fn: SortComparator = (a , b) => new Date(b[sortBy]) - new Date(a[sortBy])) { + function sort(arr: Array>, fn: SortComparator = (a , b) => Date.parse(b[sortBy]) - Date.parse(a[sortBy])) { return arr.sort(fn) } @@ -92,10 +92,7 @@ border: solid 1px black; border-collapse: collapse; overflow-y: hidden; - } - - th { - text-transform: capitalize; + width: calc(100% - 16px); } thead tr { @@ -108,6 +105,7 @@ th, td { + text-transform: capitalize; padding: 1em; border: 1px solid rgba(0, 0, 0, 1); } diff --git a/fe/src/lib/forms/AddForm.svelte b/fe/src/lib/forms/AddForm.svelte index f85cce6..bbc8356 100644 --- a/fe/src/lib/forms/AddForm.svelte +++ b/fe/src/lib/forms/AddForm.svelte @@ -11,21 +11,10 @@ const statistic: Statistic = newStatistic(); function newStatistic(): Statistic { - let now = new Date(), - month, - day, - year; - - month = `${now.getMonth() + 1}`; - day = `${now.getDate()}`; - year = now.getFullYear(); - if (month.length < 2) month = "0" + month; - if (day.length < 2) day = "0" + day; - - const date = [year, month, day].join("-"); + let date = new Date().toString(); return { - user_id: $user!.uuid, + user_id: $user!.id, date, quantity: 1 }; @@ -37,7 +26,7 @@ async function handleSubmitStat() { - const { date, quantity } = statistic; + const { user_id, date, quantity } = statistic; await fetch(apiURL("stats"), { method: "POST", headers: { @@ -45,7 +34,7 @@ }, body: JSON.stringify({ date: new Date(date), - user_id: 2, + user_id, quantity }) }); @@ -54,12 +43,12 @@ - +

Add Water

- +
@@ -75,4 +64,4 @@ -
\ No newline at end of file +
diff --git a/fe/src/lib/forms/LoginForm.svelte b/fe/src/lib/forms/LoginForm.svelte new file mode 100644 index 0000000..88d4479 --- /dev/null +++ b/fe/src/lib/forms/LoginForm.svelte @@ -0,0 +1,86 @@ + + + +
+
+ + +
+
+ + +
+ {#if error} +

{error}

+ {/if} + +
+
diff --git a/fe/src/lib/forms/PreferencesForm.svelte b/fe/src/lib/forms/PreferencesForm.svelte new file mode 100644 index 0000000..79663d1 --- /dev/null +++ b/fe/src/lib/forms/PreferencesForm.svelte @@ -0,0 +1,119 @@ + + + +

User Preferences

+
+
+ + +
+
+ + +
+ + +
+
+ + diff --git a/fe/src/lib/forms/index.ts b/fe/src/lib/forms/index.ts new file mode 100644 index 0000000..ac4e63b --- /dev/null +++ b/fe/src/lib/forms/index.ts @@ -0,0 +1,10 @@ +import AddForm from "./AddForm.svelte"; +import LoginForm from "./LoginForm.svelte"; +import PreferencesForm from "./PreferencesForm.svelte"; + + +export { + AddForm, + LoginForm, + PreferencesForm +}; \ No newline at end of file diff --git a/fe/src/types.ts b/fe/src/types.ts index c8f2f00..e06e789 100644 --- a/fe/src/types.ts +++ b/fe/src/types.ts @@ -19,7 +19,7 @@ export interface User { } export interface Statistic { - user_id: string; + user_id: number; date: string; quantity: number; } -- cgit v1.1