This commit is contained in:
2026-03-06 19:42:15 +00:00
parent abcbe3e1e5
commit 04cbb846d1
99 changed files with 11724 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import { useState, useEffect, useCallback } from 'react'
import { budgets, type Budget, type BudgetDetail } from '@/lib/api'
export function useBudgets() {
const [list, setList] = useState<Budget[]>([])
const [current, setCurrent] = useState<BudgetDetail | null>(null)
const [loading, setLoading] = useState(true)
const fetchList = useCallback(async () => {
try {
const data = await budgets.list()
setList(data)
} catch {
setList([])
} finally {
setLoading(false)
}
}, [])
const selectBudget = useCallback(async (id: string) => {
setLoading(true)
try {
const detail = await budgets.get(id)
setCurrent(detail)
} finally {
setLoading(false)
}
}, [])
useEffect(() => {
fetchList()
}, [fetchList])
return { list, current, loading, fetchList, selectBudget, setCurrent }
}