diff --git a/src/lib/components/Weight/EmptyWeightComp.svelte b/src/lib/components/Weight/EmptyWeightComp.svelte index f607090..6cf3aab 100644 --- a/src/lib/components/Weight/EmptyWeightComp.svelte +++ b/src/lib/components/Weight/EmptyWeightComp.svelte @@ -1,62 +1,33 @@ @@ -65,34 +36,14 @@ - - - - - - - diff --git a/src/lib/components/Weight/WeightComp.svelte b/src/lib/components/Weight/WeightComp.svelte index 7c3c9ac..007bdc8 100644 --- a/src/lib/components/Weight/WeightComp.svelte +++ b/src/lib/components/Weight/WeightComp.svelte @@ -1,5 +1,5 @@ diff --git a/src/lib/store/weight/dailyWeightStore.ts b/src/lib/store/weight/dailyWeightStore.ts new file mode 100644 index 0000000..1181cea --- /dev/null +++ b/src/lib/store/weight/dailyWeightStore.ts @@ -0,0 +1,20 @@ +import { type Writable, writable } from 'svelte/store' +import { type AggregatedWeight, WeightService } from '$lib/database/weight' + + +async function createStore(): Promise> { + let [rows, err] = await WeightService.GetDaily() + if (err) { + rows = [] + console.error(err) + } + + const { subscribe, update, set } = writable(rows) + return { + subscribe, + update, + set + } +} + +export const dailyWeightStore = await createStore() diff --git a/src/lib/store/weight/monthlyWeightStore.ts b/src/lib/store/weight/monthlyWeightStore.ts new file mode 100644 index 0000000..a0183ff --- /dev/null +++ b/src/lib/store/weight/monthlyWeightStore.ts @@ -0,0 +1,21 @@ +import { type Writable, writable } from 'svelte/store' +import { FoodService } from '$lib/database/food' +import type { AggregatedWeight } from '$lib/database/weight' + + +async function createStore(): Promise> { + let [rows, err] = await FoodService.GetMonthly() + if (err) { + rows = [] + console.error(err) + } + + const { subscribe, update, set } = writable(rows) + return { + subscribe, + update, + set + } +} + +export const monthlyWeightStore = await createStore() diff --git a/src/lib/store/weight/weeklyWeightStore.ts b/src/lib/store/weight/weeklyWeightStore.ts new file mode 100644 index 0000000..5a0d331 --- /dev/null +++ b/src/lib/store/weight/weeklyWeightStore.ts @@ -0,0 +1,20 @@ +import { type Writable, writable } from 'svelte/store' +import { type AggregatedWeight, WeightService } from '$lib/database/weight' + + +async function createStore(): Promise> { + let [rows, err] = await WeightService.GetWeekly() + if (err) { + rows = [] + console.error(err) + } + + const { subscribe, update, set } = writable(rows) + return { + subscribe, + update, + set + } +} + +export const weeklyWeightStore = await createStore() diff --git a/src/lib/store/weight/weightStore.ts b/src/lib/store/weight/weightStore.ts new file mode 100644 index 0000000..3fb3b94 --- /dev/null +++ b/src/lib/store/weight/weightStore.ts @@ -0,0 +1,20 @@ +import { type Writable, writable } from 'svelte/store' +import { type Weight, WeightService } from '$lib/database/weight' + + +async function createStore(): Promise> { + const rows = await WeightService.GetRecent() + const { subscribe, update, set } = writable(rows) + return { + subscribe, + update, + set, + // @ts-ignore + refresh: async () => { + const foods = await WeightService.GetRecent() + set(foods) + } + } +} + +export const weightStore = await createStore() diff --git a/src/lib/store/weight/yearlyWeightStore.ts b/src/lib/store/weight/yearlyWeightStore.ts new file mode 100644 index 0000000..1b20941 --- /dev/null +++ b/src/lib/store/weight/yearlyWeightStore.ts @@ -0,0 +1,20 @@ +import { type Writable, writable } from 'svelte/store' +import { type AggregatedWeight, WeightService } from '$lib/database/weight' + + +async function createStore(): Promise> { + let [rows, err] = await WeightService.GetYearly() + if (err) { + rows = [] + console.error(err) + } + + const { subscribe, update, set } = writable(rows) + return { + subscribe, + update, + set + } +} + +export const yearlyWeightStore = await createStore()