feat(webui): standardize content loading states
Use consistent delayed placeholders across data-backed console surfaces. Avoid flashing loading UI for fast local responses while keeping slower transitions stable. Keep failures visible and prevent gated content from opening on incomplete checks.
This commit is contained in:
22 files changed
+2493
-1527
No files matched your search
@@ -4,6 +4,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Bell, CheckCircle2, XCircle } from 'lucide-react';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useApi } from '@/lib/api';
|
||||
import { useTheme } from '@/contexts/ThemeContext';
|
||||
@@ -15,6 +16,7 @@ export function DeliveriesWidget() {
|
||||
const api = useApi();
|
||||
const { formatClock } = useTheme();
|
||||
const [records, setRecords] = useState<NotificationDeliveryRecord[] | null>(null);
|
||||
const [loadError, setLoadError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
@@ -27,10 +29,17 @@ export function DeliveriesWidget() {
|
||||
api.notifications
|
||||
.recent(50)
|
||||
.then((r) => {
|
||||
if (active) setRecords(r);
|
||||
if (active) {
|
||||
setLoadError(null);
|
||||
setRecords(r);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
if (active) setRecords((prev) => prev ?? []);
|
||||
.catch((error) => {
|
||||
console.error('load recent notification deliveries failed', error);
|
||||
if (active) {
|
||||
setLoadError(error instanceof Error ? error.message : '加载最近投递失败');
|
||||
setRecords((prev) => prev ?? []);
|
||||
}
|
||||
})
|
||||
.finally(() => { inFlight = false; });
|
||||
};
|
||||
@@ -55,40 +64,58 @@ export function DeliveriesWidget() {
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="min-h-0 flex-1 overflow-auto">
|
||||
{records === null ? (
|
||||
<p className="py-10 text-center text-sm text-muted-foreground">加载中…</p>
|
||||
) : records.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无投递记录</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 text-meta">
|
||||
{records.map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
{r.ok ? (
|
||||
<CheckCircle2 className="size-3.5 shrink-0 text-emerald-500" />
|
||||
) : (
|
||||
<XCircle className="size-3.5 shrink-0 text-destructive" />
|
||||
)}
|
||||
<span className="shrink-0 font-mono tabular-nums text-muted-foreground">{formatClock(r.time)}</span>
|
||||
<span
|
||||
className={cn(
|
||||
'shrink-0 font-medium',
|
||||
r.event === 'online' ? 'text-emerald-600' : 'text-amber-600',
|
||||
)}
|
||||
>
|
||||
{r.event === 'online' ? '上线' : '下线'}
|
||||
</span>
|
||||
<span className="shrink-0 font-mono">{r.uin}</span>
|
||||
<span className="ml-auto min-w-0 truncate text-muted-foreground" title={r.error ?? r.channelId}>
|
||||
{r.channelId}
|
||||
{!r.ok && r.error && <span className="text-xs text-destructive"> · {r.error}</span>}
|
||||
</span>
|
||||
<SkeletonSwap
|
||||
ready={records !== null}
|
||||
reserve={120}
|
||||
lines={5}
|
||||
lineHeight={24}
|
||||
label="最近投递"
|
||||
className={records !== null ? 'skeleton-swap-fluid min-h-[120px]' : ''}
|
||||
>
|
||||
{records !== null ? (
|
||||
loadError && records.length === 0 ? (
|
||||
<p role="alert" className="rounded-xl border border-destructive/30 bg-destructive/10 px-3 py-8 text-center text-sm text-destructive">
|
||||
{loadError}
|
||||
</p>
|
||||
) : records.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-xl border border-dashed py-10 text-muted-foreground">
|
||||
<Bell className="size-8 opacity-40" strokeWidth={1.5} />
|
||||
<p className="text-sm">暂无投递记录</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
) : (
|
||||
<div className="flex flex-col gap-1 text-meta">
|
||||
{loadError && (
|
||||
<p role="alert" className="mb-1 rounded-lg border border-destructive/30 bg-destructive/10 px-2 py-1.5 font-sans text-xs text-destructive">
|
||||
{loadError};当前显示上次成功读取的投递记录。
|
||||
</p>
|
||||
)}
|
||||
{records.map((r, i) => (
|
||||
<div key={i} className="flex items-center gap-2 rounded px-2 py-1 hover:bg-accent/30">
|
||||
{r.ok ? (
|
||||
<CheckCircle2 className="size-3.5 shrink-0 text-emerald-500" />
|
||||
) : (
|
||||
<XCircle className="size-3.5 shrink-0 text-destructive" />
|
||||
)}
|
||||
<span className="shrink-0 font-mono tabular-nums text-muted-foreground">{formatClock(r.time)}</span>
|
||||
<span
|
||||
className={cn(
|
||||
'shrink-0 font-medium',
|
||||
r.event === 'online' ? 'text-emerald-600' : 'text-amber-600',
|
||||
)}
|
||||
>
|
||||
{r.event === 'online' ? '上线' : '下线'}
|
||||
</span>
|
||||
<span className="shrink-0 font-mono">{r.uin}</span>
|
||||
<span className="ml-auto min-w-0 truncate text-muted-foreground" title={r.error ?? r.channelId}>
|
||||
{r.channelId}
|
||||
{!r.ok && r.error && <span className="text-xs text-destructive"> · {r.error}</span>}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : null}
|
||||
</SkeletonSwap>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user