feat: 创建首页并集成账户、交易、预算等数据,实现并行数据加载和支出统计。
This commit is contained in:
@@ -99,7 +99,7 @@ function Home() {
|
||||
getSettings().catch(() => null),
|
||||
getBudgets().catch(() => []),
|
||||
getStreakInfo().catch(() => null),
|
||||
getTransactions({ startDate: rangeStartStr, endDate: rangeEndStr, type: 'expense', pageSize: 1000 }), // Bulk fetch
|
||||
getTransactions({ startDate: rangeStartStr, endDate: rangeEndStr, pageSize: 1000 }), // Bulk fetch (All types for AI)
|
||||
]);
|
||||
|
||||
setAccounts(accountsData || []);
|
||||
@@ -111,30 +111,36 @@ function Home() {
|
||||
|
||||
// In-Memory Aggregation for Daily Spend (Fixes Timezone Issues)
|
||||
const allRangeTx = rangeTxData?.items || [];
|
||||
const expenseRangeTx = allRangeTx.filter(t => t.type === 'expense');
|
||||
|
||||
// Today
|
||||
const todayTxItems = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), today));
|
||||
// Today (Expense Only)
|
||||
const todayTxItems = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), today));
|
||||
setTodayTransactions(todayTxItems);
|
||||
setTodaySpend(calculateTotalExpense(todayTxItems));
|
||||
|
||||
// Yesterday
|
||||
const yesterdayTxItems = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), yesterday));
|
||||
// Yesterday (Expense Only)
|
||||
const yesterdayTxItems = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), yesterday));
|
||||
setYesterdaySpend(calculateTotalExpense(yesterdayTxItems));
|
||||
|
||||
// Last Week Same Day
|
||||
const lastWeekTxItems = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), lastWeekSameDay));
|
||||
// Last Week Same Day (Expense Only)
|
||||
const lastWeekTxItems = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), lastWeekSameDay));
|
||||
setLastWeekSpend(calculateTotalExpense(lastWeekTxItems));
|
||||
|
||||
// Last 7 Days Array (for chart)
|
||||
// Last 7 Days Array (for chart - Expense Only)
|
||||
const last7DaysSpendArray = [];
|
||||
const weekTxList: Transaction[] = [];
|
||||
const weekTxList: Transaction[] = []; // Filtered by date, contains ALL types
|
||||
|
||||
for (let i = 6; i >= 0; i--) {
|
||||
const d = new Date(today);
|
||||
d.setDate(d.getDate() - i);
|
||||
const dayTx = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), d));
|
||||
last7DaysSpendArray.push(calculateTotalExpense(dayTx));
|
||||
weekTxList.push(...dayTx);
|
||||
|
||||
// Expense for chart
|
||||
const dayExpenseTx = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), d));
|
||||
last7DaysSpendArray.push(calculateTotalExpense(dayExpenseTx));
|
||||
|
||||
// All types for AI
|
||||
const dayAllTx = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), d));
|
||||
weekTxList.push(...dayAllTx);
|
||||
}
|
||||
setLast7DaysSpend(last7DaysSpendArray);
|
||||
setWeekTransactions(weekTxList);
|
||||
|
||||
Reference in New Issue
Block a user