This commit is contained in:
oneao committed 2025-11-18 22:35:18 +08:00
1 parent 1445ed3b6c
commit 7419021927
19 files changed
+474 -327

No files matched your search

@@ -0,0 +1,44 @@
import type { MoneyCategoryItem } from '@/types/money/category'
import { create } from 'zustand'
interface MoneyCategoryStore {
categories: MoneyCategoryItem[]
expense: MoneyCategoryItem[]
income: MoneyCategoryItem[]
setCategories: (categories: MoneyCategoryItem[]) => void
addCategory: (category: MoneyCategoryItem) => void
removeCategory: (id: number) => void
}
export const useMoneyCategoryStore = create<MoneyCategoryStore>()(set => ({
categories: [],
expense: [],
income: [],
setCategories: categories =>
set({
categories,
expense: categories.filter(c => c.type === 0),
income: categories.filter(c => c.type === 1),
}),
addCategory: category =>
set((state) => {
const newCategories = [...state.categories, category]
return {
categories: newCategories,
expense: newCategories.filter(c => c.type === 0),
income: newCategories.filter(c => c.type === 1),
}
}),
removeCategory: id =>
set((state) => {
const newCategories = state.categories.filter(c => c.id !== id)
return {
categories: newCategories,
expense: newCategories.filter(c => c.type === 0),
income: newCategories.filter(c => c.type === 1),
}
}),
}))
@@ -0,0 +1,3 @@
import { create } from 'zustand'
import { MoneyCategoryItem } from '@/types/money/category'
import { MoneyRecordGroup, MoneyRecordItem } from '@/types/money/record'