Make all stores refresh on change

Since everything is calculated on db.......
This commit is contained in:
2024-06-15 14:08:34 +02:00
parent e81ead8e41
commit dafff6d064
15 changed files with 92 additions and 48 deletions

21
src-tauri/Cargo.lock generated
View File

@@ -2435,12 +2435,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "minisign-verify"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.3" version = "0.7.3"
@@ -4475,7 +4469,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77567d2b3b74de4588d544147142d02297f3eaa171a25a065252141d8597a516" checksum = "77567d2b3b74de4588d544147142d02297f3eaa171a25a065252141d8597a516"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.21.7",
"bytes", "bytes",
"cocoa", "cocoa",
"dirs-next", "dirs-next",
@@ -4492,7 +4485,6 @@ dependencies = [
"http", "http",
"ignore", "ignore",
"indexmap 1.9.3", "indexmap 1.9.3",
"minisign-verify",
"nix 0.26.4", "nix 0.26.4",
"notify-rust", "notify-rust",
"objc", "objc",
@@ -4521,14 +4513,12 @@ dependencies = [
"tauri-utils", "tauri-utils",
"tempfile", "tempfile",
"thiserror", "thiserror",
"time",
"tokio", "tokio",
"url", "url",
"uuid", "uuid",
"webkit2gtk", "webkit2gtk",
"webview2-com", "webview2-com",
"windows 0.39.0", "windows 0.39.0",
"zip",
] ]
[[package]] [[package]]
@@ -6289,17 +6279,6 @@ dependencies = [
"syn 2.0.66", "syn 2.0.66",
] ]
[[package]]
name = "zip"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261"
dependencies = [
"byteorder",
"crc32fast",
"crossbeam-utils",
]
[[package]] [[package]]
name = "zvariant" name = "zvariant"
version = "4.1.1" version = "4.1.1"

View File

@@ -25,7 +25,7 @@ features = ["derive"]
[dependencies.tauri] [dependencies.tauri]
version = "1.6.5" version = "1.6.5"
features = ["api-all", "devtools", "updater"] features = ["api-all", "devtools"]
[dependencies.tauri-specta] [dependencies.tauri-specta]
version = "1.0.2" version = "1.0.2"

View File

@@ -3,6 +3,7 @@
import { toast } from 'svelte-sonner' import { toast } from 'svelte-sonner'
import type { Err } from '$lib/types' import type { Err } from '$lib/types'
import { foodStore } from '$lib/store/energy/foodStore' import { foodStore } from '$lib/store/energy/foodStore'
import { RefreshStores } from '$lib/utils'
let item: Food = { let item: Food = {
food: '', food: '',
@@ -43,10 +44,7 @@
toast.error(err) toast.error(err)
return return
} }
foodStore.update((food) => { RefreshStores()
food.unshift(dbFood)
return food
})
} }
if (!per100Edited) if (!per100Edited)

View File

@@ -3,6 +3,7 @@
import type { Err } from '$lib/types' import type { Err } from '$lib/types'
import { type Weight, WeightService } from '$lib/database/weight' import { type Weight, WeightService } from '$lib/database/weight'
import { weightStore } from '$lib/store/weight/weightStore' import { weightStore } from '$lib/store/weight/weightStore'
import { RefreshStores } from '$lib/utils'
let item: Weight = { let item: Weight = {
weight: 0 weight: 0
@@ -24,10 +25,7 @@
toast.error(err) toast.error(err)
return return
} }
weightStore.update((weight) => { RefreshStores()
weight.unshift(dbRow)
return weight
})
} }
} }
</script> </script>

View File

@@ -2,8 +2,8 @@
import { foodStore } from '$lib/store/energy/foodStore' import { foodStore } from '$lib/store/energy/foodStore'
import FoodTable from '$components/Energy/Food/FoodTable.svelte' import FoodTable from '$components/Energy/Food/FoodTable.svelte'
import { lookbackDaysStore } from '$lib/store/energy/lookbackDaysStore' import { lookbackDaysStore } from '$lib/store/energy/lookbackDaysStore'
// @ts-ignore import { RefreshStores } from '$lib/utils'
lookbackDaysStore.subscribe((n) => foodStore.refresh()) lookbackDaysStore.subscribe((n) => RefreshStores())
</script> </script>
<template> <template>

View File

@@ -1,11 +1,6 @@
<script lang="ts"> <script lang="ts">
import { foodStore } from '$lib/store/energy/foodStore'
import FoodTable from '$components/Energy/Food/FoodTable.svelte'
import { lookbackDaysStore } from '$lib/store/energy/lookbackDaysStore'
import WeightTable from '$components/Weight/WeightTable.svelte' import WeightTable from '$components/Weight/WeightTable.svelte'
import { weightStore } from '$lib/store/weight/weightStore' import { weightStore } from '$lib/store/weight/weightStore'
// @ts-ignore
lookbackDaysStore.subscribe((n) => weightStore.refresh())
</script> </script>
<template> <template>

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedFood[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await FoodService.GetDaily()
set(rows[0])
}
} }
} }

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedFood[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await FoodService.GetMonthly()
set(rows[0])
}
} }
} }

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedFood[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await FoodService.GetWeekly()
set(rows[0])
}
} }
} }

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedFood[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await FoodService.GetYearly()
set(rows[0])
}
} }
} }

View File

@@ -1,5 +1,6 @@
import { type Writable, writable } from 'svelte/store' import { type Writable, writable } from 'svelte/store'
import { type AggregatedWeight, WeightService } from '$lib/database/weight' import { type AggregatedWeight, WeightService } from '$lib/database/weight'
import { FoodService } from '$lib/database/food'
async function createStore(): Promise<Writable<AggregatedWeight[]>> { async function createStore(): Promise<Writable<AggregatedWeight[]>> {
@@ -13,7 +14,12 @@ async function createStore(): Promise<Writable<AggregatedWeight[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await WeightService.GetDaily()
set(rows[0])
}
} }
} }

View File

@@ -1,10 +1,9 @@
import { type Writable, writable } from 'svelte/store' import { type Writable, writable } from 'svelte/store'
import { FoodService } from '$lib/database/food' import { type AggregatedWeight, WeightService } from '$lib/database/weight'
import type { AggregatedWeight } from '$lib/database/weight'
async function createStore(): Promise<Writable<AggregatedWeight[]>> { async function createStore(): Promise<Writable<AggregatedWeight[]>> {
let [rows, err] = await FoodService.GetMonthly() let [rows, err] = await WeightService.GetMonthly()
if (err) { if (err) {
rows = [] rows = []
console.error(err) console.error(err)
@@ -14,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedWeight[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await WeightService.GetMonthly()
set(rows[0])
}
} }
} }

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedWeight[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await WeightService.GetWeekly()
set(rows[0])
}
} }
} }

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedWeight[]>> {
return { return {
subscribe, subscribe,
update, update,
set set,
// @ts-ignore
refresh: async () => {
const rows = await WeightService.GetYearly()
set(rows[0])
}
} }
} }

View File

@@ -2,6 +2,16 @@ import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge' import { twMerge } from 'tailwind-merge'
import { cubicOut } from 'svelte/easing' import { cubicOut } from 'svelte/easing'
import type { TransitionConfig } from 'svelte/transition' import type { TransitionConfig } from 'svelte/transition'
import { dailyFoodStore } from '$lib/store/energy/dailyFoodStore'
import { foodStore } from '$lib/store/energy/foodStore'
import { weeklyFoodStore } from '$lib/store/energy/weeklyFoodStore'
import { monthlyFoodStore } from '$lib/store/energy/monthlyFoodStore'
import { yearlyFoodStore } from '$lib/store/energy/yearlyFoodStore'
import { weightStore } from '$lib/store/weight/weightStore'
import { dailyWeightStore } from '$lib/store/weight/dailyWeightStore'
import { weeklyWeightStore } from '$lib/store/weight/weeklyWeightStore'
import { monthlyWeightStore } from '$lib/store/weight/monthlyWeightStore'
import { yearlyWeightStore } from '$lib/store/weight/yearlyWeightStore'
export function cn(...inputs: ClassValue[]) { export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs)) return twMerge(clsx(inputs))
@@ -110,3 +120,27 @@ function GenerateColor(): string {
} }
export { GenerateColor } export { GenerateColor }
export function RefreshStores() {
// @ts-ignore
foodStore.refresh()
// @ts-ignore
dailyFoodStore.refresh()
// @ts-ignore
weeklyFoodStore.refresh()
// @ts-ignore
monthlyFoodStore.refresh()
// @ts-ignore
yearlyFoodStore.refresh()
// @ts-ignore
weightStore.refresh()
// @ts-ignore
dailyWeightStore.refresh()
// @ts-ignore
weeklyWeightStore.refresh()
// @ts-ignore
monthlyWeightStore.refresh()
// @ts-ignore
yearlyWeightStore.refresh()
}