diff --git a/src/Dashboard.tsx b/src/Dashboard.tsx index d961c52..7110ade 100644 --- a/src/Dashboard.tsx +++ b/src/Dashboard.tsx @@ -130,7 +130,7 @@ export default function Dashboard() { diff --git a/src/components/HistoryChart.tsx b/src/components/HistoryChart.tsx index c46f374..29c06fb 100644 --- a/src/components/HistoryChart.tsx +++ b/src/components/HistoryChart.tsx @@ -44,14 +44,14 @@ export default function HistoryChart({ if (amount === 0) return ""; - if (tab === "year") { + if (tab === "monthly") { if (amount >= 100000) { return `₹ ${(amount / 100000).toFixed(2)} L`; } return `₹ ${amount.toLocaleString("en-IN")}`; } - if (tab === "month") { + if (tab === "weekly") { if (amount >= 1000) { return `₹ ${(amount / 1000).toFixed(1)} K`; } diff --git a/src/utils/dashboardLoader.ts b/src/utils/dashboardLoader.ts index 6e54e62..f16e152 100644 --- a/src/utils/dashboardLoader.ts +++ b/src/utils/dashboardLoader.ts @@ -96,7 +96,7 @@ export async function fetchAggregatedData( const normalize = (amt: number) => Math.abs(amt); // ---------------- WEEK ---------------- - const weekBuckets: Record = { + const dailyBuckets: Record = { Mon: 0, Tue: 0, Wed: 0, Thu: 0, Fri: 0, Sat: 0, Sun: 0 }; @@ -105,7 +105,7 @@ export async function fetchAggregatedData( const weekEnd = endOfDay(new Date(weekStart.getTime() + 6 * 86400000)); // ---------------- MONTH (rolling 5 weeks, Mon–Sun aligned) ---------------- - const monthBuckets: { + const weeklyBuckets: { label: string; start: Date; end: Date; @@ -118,7 +118,7 @@ export async function fetchAggregatedData( const start = new Date(currentWeekStart.getTime() - i * 7 * 86400000); const end = endOfDay(new Date(start.getTime() + 6 * 86400000)); - monthBuckets.push({ + weeklyBuckets.push({ label: `${format(start)} - ${format(end)}`, start, end, @@ -127,7 +127,7 @@ export async function fetchAggregatedData( } // ---------------- YEAR (rolling 12 months) ---------------- - const yearBuckets: { + const monthlyBuckets: { label: string; start: Date; end: Date; @@ -149,7 +149,7 @@ export async function fetchAggregatedData( month: "short" })}-${String(d.getFullYear()).slice(2)}`; - yearBuckets.push({ + monthlyBuckets.push({ label, start, end, @@ -176,20 +176,20 @@ export async function fetchAggregatedData( // WEEK if (d >= weekStart && d <= weekEnd) { const day = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"][d.getDay()]; - if (weekBuckets[day] !== undefined) { - weekBuckets[day] += amt; + if (dailyBuckets[day] !== undefined) { + dailyBuckets[day] += amt; } } // MONTH (rolling weeks) - for (const b of monthBuckets) { + for (const b of weeklyBuckets) { if (d >= b.start && d <= b.end) { b.amount += amt; } } // YEAR (rolling months) - for (const b of yearBuckets) { + for (const b of monthlyBuckets) { if (d >= b.start && d <= b.end) { b.amount += amt; } @@ -208,9 +208,9 @@ export async function fetchAggregatedData( })); const chartData = { - week: toPoints(weekBuckets), - month: toPoints(monthBuckets), - year: toPoints(yearBuckets) + daily: toPoints(dailyBuckets), + weekly: toPoints(weeklyBuckets), + monthly: toPoints(monthlyBuckets) }; // highlight max