From 552788f4ba10b6bb7b33f6cbb5487bf2de97987b Mon Sep 17 00:00:00 2001 From: admin <1297598740@qq.com> Date: Thu, 29 Jan 2026 10:15:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=B9=B6=E9=9B=86=E6=88=90=E8=B4=A6=E6=88=B7=E3=80=81=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E3=80=81=E9=A2=84=E7=AE=97=E7=AD=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E7=8E=B0=E5=B9=B6=E8=A1=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=92=8C=E6=94=AF=E5=87=BA=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Home/Home.tsx | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index bdb0259..f7037a9 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -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);