replace redux with zustand

This commit is contained in:
2025-07-25 01:03:11 +02:00
parent 5448285211
commit 3bcd2e16a2
30 changed files with 510 additions and 534 deletions

26
src/store/flatastic.ts Normal file
View File

@@ -0,0 +1,26 @@
import { create } from "zustand";
import Flatastic from "@/api/flatastic";
import type { FlatasticChore } from "@/types/flatasticChore";
interface FlatasticStore {
chores: FlatasticChore[];
fetch: () => Promise<void>;
}
const useFlatasticStore = create<FlatasticStore>(
(set: (state: Partial<FlatasticStore>) => void) => ({
chores: [],
fetch: async () => {
if (!import.meta.env.VITE_FLATTASTIC_API_KEY) {
throw new Error("Flatastic API Key is not set");
}
const flatastic = new Flatastic(import.meta.env.VITE_FLATTASTIC_API_KEY);
const data = await flatastic.getTaskList();
console.log("Flatastic chores fetched:", data);
set({ chores: data as FlatasticChore[] });
},
}),
);
export { useFlatasticStore };