Compare commits
2 Commits
71ba700322
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f213a9455b | |||
| 009ab50b47 |
@@ -58,19 +58,28 @@ export default function HistoryChartView(props: ViewProps) {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isDark = theme.palette.mode === "dark";
|
const isDark = theme.palette.mode === "dark";
|
||||||
|
|
||||||
|
const total = currentData.length;
|
||||||
|
const maxStartIndex = Math.max(total - visibleCount, 0);
|
||||||
|
const clampedStartIndex = Math.min(startIndex, maxStartIndex);
|
||||||
|
|
||||||
const handleTabChange = (_: React.MouseEvent<HTMLElement>, newTab: string | null) => {
|
const handleTabChange = (_: React.MouseEvent<HTMLElement>, newTab: string | null) => {
|
||||||
if (newTab !== null) setActiveTab(newTab);
|
if (newTab !== null) setActiveTab(newTab);
|
||||||
};
|
};
|
||||||
|
|
||||||
const canGoLeft = startIndex > 0;
|
const canGoLeft = clampedStartIndex > 0;
|
||||||
const canGoRight = startIndex + visibleCount < currentData.length;
|
const canGoRight = clampedStartIndex < maxStartIndex;
|
||||||
|
|
||||||
const handlePrev = () => {
|
const handlePrev = () => {
|
||||||
if (canGoLeft) setStartIndex((prev) => prev - visibleCount);
|
if (!canGoLeft) return;
|
||||||
|
setStartIndex((prev) => Math.max(prev - visibleCount, 0));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNext = () => {
|
const handleNext = () => {
|
||||||
if (canGoRight) setStartIndex((prev) => prev + visibleCount);
|
if (!canGoRight) return;
|
||||||
|
setStartIndex((prev) => {
|
||||||
|
const next = prev + visibleCount;
|
||||||
|
return Math.min(next, maxStartIndex);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -76,14 +76,24 @@ export default function TopTags({
|
|||||||
|
|
||||||
arr.sort((a, b) => b.amount - a.amount);
|
arr.sort((a, b) => b.amount - a.amount);
|
||||||
|
|
||||||
const top = arr.slice(0, 5);
|
const top = arr.slice(0, 4);
|
||||||
const total = top.reduce((sum, t) => sum + t.amount, 0);
|
const total = top.reduce((sum, t) => sum + t.amount, 0);
|
||||||
|
|
||||||
return { items: top, total };
|
return { items: top, total };
|
||||||
}, [reportData, mode, selectedPeriodId]);
|
}, [reportData, mode, selectedPeriodId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "grid", gap: 2 }}>
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: {
|
||||||
|
xs: "1fr",
|
||||||
|
sm: "repeat(2, 1fr)",
|
||||||
|
md: "repeat(4, 1fr)"
|
||||||
|
},
|
||||||
|
gap: 2
|
||||||
|
}}
|
||||||
|
>
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<ProgressCard
|
<ProgressCard
|
||||||
key={item.tag}
|
key={item.tag}
|
||||||
@@ -91,6 +101,7 @@ export default function TopTags({
|
|||||||
progressAmount={item.amount}
|
progressAmount={item.amount}
|
||||||
totalAmount={total}
|
totalAmount={total}
|
||||||
compact={compact}
|
compact={compact}
|
||||||
|
colorTheme={mode === "expense" ? "error" : "success"}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -83,10 +83,7 @@ function buildLabel(
|
|||||||
return `${dayFmt.format(start)} - ${dayFmt.format(end)}`;
|
return `${dayFmt.format(start)} - ${dayFmt.format(end)}`;
|
||||||
|
|
||||||
case "monthly":
|
case "monthly":
|
||||||
if (sameMonth(start, end)) {
|
|
||||||
return `${monthFmt.format(start)} ${yearFmt.format(start)}`;
|
return `${monthFmt.format(start)} ${yearFmt.format(start)}`;
|
||||||
}
|
|
||||||
return `${monthDayFmt.format(start)} - ${monthDayFmt.format(end)}`;
|
|
||||||
|
|
||||||
case "yearly":
|
case "yearly":
|
||||||
return yearFmt.format(start);
|
return yearFmt.format(start);
|
||||||
@@ -110,8 +107,8 @@ function decoratePeriods(
|
|||||||
): (ReportPeriod & { id: string; label: string })[] {
|
): (ReportPeriod & { id: string; label: string })[] {
|
||||||
return periods.map((p) => ({
|
return periods.map((p) => ({
|
||||||
...p,
|
...p,
|
||||||
id: buildPeriodId(type, new Date(p.start), new Date(p.end)),
|
id: buildPeriodId(type, new Date(p.start + "Z"), new Date(p.end + "Z")),
|
||||||
label: buildLabel(type, new Date(p.start), new Date(p.end)),
|
label: buildLabel(type, new Date(p.start + "Z"), new Date(p.end + "Z")),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user