Skip to content

Commit 5471a20

Browse files
committed
fix: align data usage chart period logic and add loading state
1 parent e9d63ed commit 5471a20

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

dashboard/src/components/dashboard/data-usage-chart.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,17 @@ const DataUsageChart = ({ admin_username }: { admin_username?: string }) => {
160160
} else if (periodOption.hours) {
161161
start = now.subtract(periodOption.hours, 'hour')
162162
} else if (periodOption.days) {
163-
start = now.subtract(periodOption.days, 'day')
163+
// Match the logic from CostumeBarChart.tsx and AllNodesStackedBarChart.tsx
164+
// For 7d, subtract 6 days; for 3d, subtract 2 days
165+
const daysToSubtract = periodOption.days === 7 ? 6 : periodOption.days === 3 ? 2 : periodOption.days
166+
start = now.subtract(daysToSubtract, 'day')
164167
} else {
165168
start = now
166169
}
167170
return { startDate: start.toISOString(), endDate: now.toISOString() }
168171
}, [periodOption])
169172

170-
const { data } = useGetUsersUsage(
173+
const { data, isLoading } = useGetUsersUsage(
171174
{
172175
...(admin_username ? { admin: [admin_username] } : {}),
173176
period: periodOption.period,
@@ -229,7 +232,29 @@ const DataUsageChart = ({ admin_username }: { admin_username?: string }) => {
229232
</Select>
230233
</CardHeader>
231234
<CardContent className="flex-1 flex flex-col justify-center p-2 sm:p-6">
232-
{chartData.length === 0 ? (
235+
{isLoading ? (
236+
<div className="w-full max-w-7xl mx-auto">
237+
<div className="max-h-[320px] min-h-[200px] w-full">
238+
<div className="flex flex-col h-full">
239+
<div className="flex-1">
240+
<div className="h-full flex items-end justify-center">
241+
<div className="flex gap-2 h-48 items-end">
242+
{[1, 2, 3, 4, 5, 6, 7].map((i) => (
243+
<div key={i} className="animate-pulse">
244+
<div className={`bg-muted rounded-t-lg w-8 ${i === 4 ? 'h-32' : i === 3 || i === 5 ? 'h-24' : i === 2 || i === 6 ? 'h-16' : 'h-20'}`} />
245+
</div>
246+
))}
247+
</div>
248+
</div>
249+
</div>
250+
<div className="flex justify-between mt-4">
251+
<div className="w-16 h-4 bg-muted rounded animate-pulse" />
252+
<div className="w-16 h-4 bg-muted rounded animate-pulse" />
253+
</div>
254+
</div>
255+
</div>
256+
</div>
257+
) : chartData.length === 0 ? (
233258
<div className="mt-16 flex flex-col items-center justify-center gap-4 text-muted-foreground min-h-[200px]">
234259
<SearchXIcon className="size-16" strokeWidth={1} />
235260
{t('admins.monitor.no_traffic', { defaultValue: 'No traffic data available' })}

0 commit comments

Comments
 (0)