-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.ts
52 lines (50 loc) · 1.63 KB
/
store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* eslint-disable no-unused-vars */
import { persist } from "zustand/middleware";
import { create } from "zustand";
export type ListState = {
currentTotal: number;
sort: {
asc: boolean;
by: "created_at" | "amount";
};
hideAmounts: boolean;
dailyProgressDays: number;
showLogs: boolean;
monthlyTotalBy: "last" | "avg";
showAIDialog: boolean;
lastAIOutput: string | null;
setLastAIOutput: (ai: string) => void;
setShowAIDialog: () => void;
setCurrentTotal: (total: number) => void;
setSort: (asc: boolean, by: "created_at" | "amount") => void;
toggleHideAmounts: () => void;
setDailyProgressDays: (days: number) => void;
setMonthlyTotalBy: (by: "last" | "avg") => void;
setShowLogs: () => void;
};
export const useListState = create<ListState>()(
persist(
(set, get) => ({
sort: {
asc: false,
by: "created_at",
},
setSort: (asc, by) => set(() => ({ sort: { asc, by } })),
hideAmounts: false,
toggleHideAmounts: () => set({ hideAmounts: !get().hideAmounts }),
dailyProgressDays: 28,
setDailyProgressDays: (days) => set(() => ({ dailyProgressDays: days })),
showLogs: true,
monthlyTotalBy: "last",
lastAIOutput: null,
setLastAIOutput: (ai) => set(() => ({ lastAIOutput: ai })),
setMonthlyTotalBy: (by) => set(() => ({ monthlyTotalBy: by })),
setShowLogs: () => set({ showLogs: !get().showLogs }),
currentTotal: 0,
setCurrentTotal: (total) => set({ currentTotal: total }),
showAIDialog: false,
setShowAIDialog: () => set({ showAIDialog: !get().showAIDialog }),
}),
{ name: "list-page" },
),
);