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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,11 +1,6 @@
<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 { weightStore } from '$lib/store/weight/weightStore'
// @ts-ignore
lookbackDaysStore.subscribe((n) => weightStore.refresh())
</script>
<template>

View File

@@ -13,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedFood[]>> {
return {
subscribe,
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 {
subscribe,
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 {
subscribe,
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 {
subscribe,
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 AggregatedWeight, WeightService } from '$lib/database/weight'
import { FoodService } from '$lib/database/food'
async function createStore(): Promise<Writable<AggregatedWeight[]>> {
@@ -13,7 +14,12 @@ async function createStore(): Promise<Writable<AggregatedWeight[]>> {
return {
subscribe,
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 { FoodService } from '$lib/database/food'
import type { AggregatedWeight } from '$lib/database/weight'
import { type AggregatedWeight, WeightService } from '$lib/database/weight'
async function createStore(): Promise<Writable<AggregatedWeight[]>> {
let [rows, err] = await FoodService.GetMonthly()
let [rows, err] = await WeightService.GetMonthly()
if (err) {
rows = []
console.error(err)
@@ -14,7 +13,12 @@ async function createStore(): Promise<Writable<AggregatedWeight[]>> {
return {
subscribe,
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 {
subscribe,
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 {
subscribe,
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 { cubicOut } from 'svelte/easing'
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[]) {
return twMerge(clsx(inputs))
@@ -110,3 +120,27 @@ function GenerateColor(): string {
}
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()
}