Implement weight stores
This commit is contained in:
@@ -31,7 +31,7 @@ async function createStore(): Promise<Writable<main.AggregatedFood[]>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const dailyFoodStore = await createStore();
|
const dailyFoodStore = await createStore();
|
||||||
settingsStore.subscribe((settings) => {
|
settingsStore.subscribe(() => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
dailyFoodStore.refresh();
|
dailyFoodStore.refresh();
|
||||||
});
|
});
|
||||||
|
@@ -31,7 +31,7 @@ async function createStore(): Promise<Writable<main.Food[]>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const foodStore = await createStore();
|
const foodStore = await createStore();
|
||||||
settingsStore.subscribe((settings) => {
|
settingsStore.subscribe(() => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
foodStore.refresh();
|
foodStore.refresh();
|
||||||
});
|
});
|
||||||
|
@@ -31,7 +31,7 @@ async function createStore(): Promise<Writable<main.AggregatedFood[]>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const monthlyFoodStore = await createStore();
|
const monthlyFoodStore = await createStore();
|
||||||
settingsStore.subscribe((settings) => {
|
settingsStore.subscribe(() => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
monthlyFoodStore.refresh();
|
monthlyFoodStore.refresh();
|
||||||
});
|
});
|
||||||
|
@@ -31,7 +31,7 @@ async function createStore(): Promise<Writable<main.AggregatedFood[]>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const weeklyFoodStore = await createStore();
|
const weeklyFoodStore = await createStore();
|
||||||
settingsStore.subscribe((settings) => {
|
settingsStore.subscribe(() => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
weeklyFoodStore.refresh();
|
weeklyFoodStore.refresh();
|
||||||
});
|
});
|
||||||
|
@@ -31,7 +31,7 @@ async function createStore(): Promise<Writable<main.AggregatedFood[]>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const yearlyFoodStore = await createStore();
|
const yearlyFoodStore = await createStore();
|
||||||
settingsStore.subscribe((settings) => {
|
settingsStore.subscribe(() => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
yearlyFoodStore.refresh();
|
yearlyFoodStore.refresh();
|
||||||
});
|
});
|
||||||
|
39
frontend/src/lib/store/Weight/dailyWeightStore.ts
Normal file
39
frontend/src/lib/store/Weight/dailyWeightStore.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { type Writable, writable } from "svelte/store";
|
||||||
|
import { main } from "$wails/models";
|
||||||
|
import { GetDailyWeight } from "$wails/main/App";
|
||||||
|
import { toast } from "svelte-sonner";
|
||||||
|
import { settingsStore } from "../settingsStore";
|
||||||
|
|
||||||
|
async function createStore(): Promise<Writable<main.AggregatedWeight[]>> {
|
||||||
|
let weights: main.AggregatedWeight[] = [];
|
||||||
|
let res: main.WailsAggregateWeight = await GetDailyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
} else {
|
||||||
|
weights = res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscribe, update, set } = writable(weights);
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
update,
|
||||||
|
set,
|
||||||
|
// @ts-ignore
|
||||||
|
refresh: async () => {
|
||||||
|
const res = await GetDailyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set(res.data);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const dailyWeightStore = await createStore();
|
||||||
|
settingsStore.subscribe(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
dailyWeightStore.refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
export { dailyWeightStore };
|
39
frontend/src/lib/store/Weight/monthlyWeightStore.ts
Normal file
39
frontend/src/lib/store/Weight/monthlyWeightStore.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { type Writable, writable } from "svelte/store";
|
||||||
|
import { main } from "$wails/models";
|
||||||
|
import { GetMonthlyWeight } from "$wails/main/App";
|
||||||
|
import { toast } from "svelte-sonner";
|
||||||
|
import { settingsStore } from "../settingsStore";
|
||||||
|
|
||||||
|
async function createStore(): Promise<Writable<main.AggregatedWeight[]>> {
|
||||||
|
let weights: main.AggregatedWeight[] = [];
|
||||||
|
let res: main.WailsAggregateWeight = await GetMonthlyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
} else {
|
||||||
|
weights = res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscribe, update, set } = writable(weights);
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
update,
|
||||||
|
set,
|
||||||
|
// @ts-ignore
|
||||||
|
refresh: async () => {
|
||||||
|
const res = await GetMonthlyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set(res.data);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const monthlyWeightStore = await createStore();
|
||||||
|
settingsStore.subscribe(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
monthlyWeightStore.refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
export { monthlyWeightStore };
|
39
frontend/src/lib/store/Weight/weeklyWeightStore.ts
Normal file
39
frontend/src/lib/store/Weight/weeklyWeightStore.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { type Writable, writable } from "svelte/store";
|
||||||
|
import { main } from "$wails/models";
|
||||||
|
import { GetWeeklyWeight } from "$wails/main/App";
|
||||||
|
import { toast } from "svelte-sonner";
|
||||||
|
import { settingsStore } from "../settingsStore";
|
||||||
|
|
||||||
|
async function createStore(): Promise<Writable<main.AggregatedWeight[]>> {
|
||||||
|
let weights: main.AggregatedWeight[] = [];
|
||||||
|
let res: main.WailsAggregateWeight = await GetWeeklyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
} else {
|
||||||
|
weights = res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscribe, update, set } = writable(weights);
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
update,
|
||||||
|
set,
|
||||||
|
// @ts-ignore
|
||||||
|
refresh: async () => {
|
||||||
|
const res = await GetWeeklyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set(res.data);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const weeklyWeightStore = await createStore();
|
||||||
|
settingsStore.subscribe(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
weeklyWeightStore.refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
export { weeklyWeightStore };
|
39
frontend/src/lib/store/Weight/weightStore.ts
Normal file
39
frontend/src/lib/store/Weight/weightStore.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { type Writable, writable } from "svelte/store";
|
||||||
|
import { main } from "$wails/models";
|
||||||
|
import { GetWeight } from "$wails/main/App";
|
||||||
|
import { toast } from "svelte-sonner";
|
||||||
|
import { settingsStore } from "../settingsStore";
|
||||||
|
|
||||||
|
async function createStore(): Promise<Writable<main.Weight[]>> {
|
||||||
|
let weights: main.Weight[] = [];
|
||||||
|
let res: main.WailsWeight = await GetWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
} else {
|
||||||
|
weights = res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscribe, update, set } = writable(weights);
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
update,
|
||||||
|
set,
|
||||||
|
// @ts-ignore
|
||||||
|
refresh: async () => {
|
||||||
|
const res = await GetWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set(res.data);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const weightStore = await createStore();
|
||||||
|
settingsStore.subscribe(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
weightStore.refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
export { weightStore };
|
39
frontend/src/lib/store/Weight/yearlyWeightStore.ts
Normal file
39
frontend/src/lib/store/Weight/yearlyWeightStore.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { type Writable, writable } from "svelte/store";
|
||||||
|
import { main } from "$wails/models";
|
||||||
|
import { GetYearlyWeight } from "$wails/main/App";
|
||||||
|
import { toast } from "svelte-sonner";
|
||||||
|
import { settingsStore } from "../settingsStore";
|
||||||
|
|
||||||
|
async function createStore(): Promise<Writable<main.AggregatedWeight[]>> {
|
||||||
|
let weights: main.AggregatedWeight[] = [];
|
||||||
|
let res: main.WailsAggregateWeight = await GetYearlyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
} else {
|
||||||
|
weights = res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { subscribe, update, set } = writable(weights);
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
update,
|
||||||
|
set,
|
||||||
|
// @ts-ignore
|
||||||
|
refresh: async () => {
|
||||||
|
const res = await GetYearlyWeight();
|
||||||
|
if (!res.success) {
|
||||||
|
toast.error(`Failed to get weights with error: ${res.error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set(res.data);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const yearlyWeightStore = await createStore();
|
||||||
|
settingsStore.subscribe(() => {
|
||||||
|
// @ts-ignore
|
||||||
|
yearlyWeightStore.refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
export { yearlyWeightStore };
|
Reference in New Issue
Block a user