feat(webui): report account storage update progress

Surface account storage preparation and background history progress through the existing live connection status channel. Clearly distinguish unavailable accounts from accounts that remain fully usable during maintenance.

Show processed totals, completion percentage, estimated remaining time, and retry states in both the global notice and account overview. Preserve existing connection update filtering to avoid unnecessary refreshes.
This commit is contained in:
DrSmoothl committed 2026-07-30 09:57:31 +08:00
1 parent 25e61ce5df
commit e5f256f4dc
7 files changed
+202 -27

No files matched your search

@@ -15,10 +15,11 @@ import { cn } from '@/lib/utils';
interface MainLayoutProps {
status: string;
onLogout: () => void;
notice?: ReactNode;
children: ReactNode;
}
export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
export function MainLayout({ status, onLogout, notice, children }: MainLayoutProps) {
const isMobile = !useMediaQuery('(min-width: 768px)');
const { appearance } = useTheme();
const customBg = appearance.background.type !== 'none';
@@ -123,6 +124,8 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
/>
)}
{!kiosk && notice}
<main className={cn('flex min-h-0 flex-1 flex-col')}>
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
<div className="mx-auto w-full max-w-7xl px-4 py-5 sm:px-6 sm:py-6 lg:px-8 2xl:max-w-[1600px]">
@@ -15,7 +15,14 @@ import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Skeleton } from '@/components/ui/skeleton';
import { cn, formatBytes, formatUptime } from '@/lib/utils';
import type { AppPath } from '@/router';
import type { AdapterStatus, AdapterStatusLevel, LogEntry, LogLevel, UiLayoutItem } from '@/types';
import type {
AccountDatabaseMigration,
AdapterStatus,
AdapterStatusLevel,
LogEntry,
LogLevel,
UiLayoutItem,
} from '@/types';
import { useApi } from '@/lib/api';
import { useAppState } from '@/contexts/AppStateContext';
import { useSession } from '@/contexts/SessionContext';
@@ -875,9 +882,10 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
<span className="text-sm font-semibold">{acc.nickname || acc.uin}</span>
<span className="font-mono text-meta text-muted-foreground tabular-nums">{acc.uin}</span>
</div>
{acc.adapters.length === 0 ? (
<p className="rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground">未配置任何协议端点</p>
) : (
{acc.databaseMigration && acc.databaseMigration.phase !== 'complete' && (
<DatabaseMigrationProgress migration={acc.databaseMigration} />
)}
{acc.adapters.length > 0 ? (
<div className="flex flex-col gap-1.5">
{acc.adapters.map((adp) => (
<div key={adp.name} className="flex items-center gap-2 rounded-xl border bg-card/40 px-3 py-2">
@@ -899,7 +907,9 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
</div>
))}
</div>
)}
) : acc.databaseMigration?.usable !== false ? (
<p className="rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground">未配置任何协议端点</p>
) : null}
</div>
))}
</div>
@@ -909,6 +919,53 @@ function ConnectionsBlock({ config }: { config: ConnectionsConfig }) {
);
}
function DatabaseMigrationProgress({ migration }: { migration: AccountDatabaseMigration }) {
const percentage = migration.progress === null
? null
: Math.round(migration.progress * 100);
const title = migration.phase === 'preparing'
? '正在准备数据库,账号暂不可用'
: migration.phase === 'failed'
? (migration.usable ? '历史数据迁移失败,账号功能可用' : '数据库准备失败,账号暂不可用')
: '正在后台迁移历史数据,账号功能可用';
const eta = formatMigrationEta(migration.estimatedRemainingSeconds);
return (
<div className={cn(
'rounded-xl border px-3 py-2.5',
migration.phase === 'failed'
? 'border-destructive/25 bg-destructive/5'
: 'border-warning/25 bg-warning/5',
)}>
<div className="flex items-center justify-between gap-3 text-xs">
<span className="font-medium">{title}</span>
{percentage !== null && <span className="tabular-nums">{percentage}%</span>}
</div>
{percentage !== null && <Progress className="mt-2 h-1.5" value={percentage} />}
<div className="mt-1.5 flex flex-wrap gap-x-3 gap-y-1 text-meta text-muted-foreground">
{migration.total !== null && (
<span className="tabular-nums">
已处理 {migration.processed.toLocaleString()} / {migration.total.toLocaleString()} 条
</span>
)}
{migration.phase !== 'failed' && <span>{eta}</span>}
{migration.phase === 'failed' && migration.error && <span>{migration.error}</span>}
</div>
</div>
);
}
function formatMigrationEta(seconds: number | null): string {
if (seconds === null) return '剩余时间估算中';
if (seconds <= 0) return '即将完成';
if (seconds < 60) return `预计剩余 ${seconds} 秒`;
const minutes = Math.ceil(seconds / 60);
if (minutes < 60) return `预计剩余 ${minutes} 分钟`;
const hours = Math.floor(minutes / 60);
const remainder = minutes % 60;
return `预计剩余 ${hours} 小时${remainder > 0 ? ` ${remainder} 分钟` : ''}`;
}
// ─────────────── static widgets (note / link / account) ───────────────
function NoteWidget({ config }: { config: NoteConfig }) {
+33 -2
View File
@@ -1,4 +1,4 @@
import { Suspense, useCallback, useEffect, useRef, useState } from 'react';
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Outlet, useNavigate, useRouterState } from '@tanstack/react-router';
import { useTheme } from '@/contexts/ThemeContext';
import { useApi } from '@/lib/api';
@@ -219,6 +219,37 @@ export function AppLayout() {
session.onLogoutComplete();
}, [api, session]);
const migrationNotice = useMemo(() => {
const active = connections.filter((account) => {
const phase = account.databaseMigration?.phase;
return phase && phase !== 'complete';
});
if (active.length === 0) return null;
const preparing = active.filter((account) => account.databaseMigration?.phase === 'preparing').length;
const migrating = active.filter((account) => account.databaseMigration?.phase === 'migrating').length;
const failedUsable = active.filter((account) => (
account.databaseMigration?.phase === 'failed' && account.databaseMigration.usable
)).length;
const failedUnavailable = active.filter((account) => (
account.databaseMigration?.phase === 'failed' && !account.databaseMigration.usable
)).length;
const parts = [
...(preparing > 0 ? [`${preparing} 个账号正在准备数据库,暂不可用`] : []),
...(migrating > 0 ? [`${migrating} 个账号正在后台迁移,功能可用`] : []),
...(failedUsable > 0 ? [`${failedUsable} 个可用账号迁移失败,将自动重试`] : []),
...(failedUnavailable > 0 ? [`${failedUnavailable} 个账号数据库准备失败,暂不可用并将自动重试`] : []),
];
return (
<div
role="status"
className="border-b border-warning/25 bg-warning/10 px-4 py-2.5 text-sm text-warning-foreground sm:px-6 lg:px-8"
>
<span className="font-medium">账号数据库状态:</span>
{parts.join(';')}。请查看概览详情。
</div>
);
}, [connections]);
return (
<AppStateProvider
value={{
@@ -240,7 +271,7 @@ export function AppLayout() {
<LayoutProvider>
<KioskProvider>
<DefaultRouteRedirect />
<MainLayout status={session.status} onLogout={handleLogout}>
<MainLayout status={session.status} onLogout={handleLogout} notice={migrationNotice}>
{/* Routes use `lazyRouteComponent` (router/index.tsx) for
code-splitting, which suspends until the chunk is fetched.
The chrome (sidebar / top bar) stays mounted across this
+11
View File
@@ -38,10 +38,21 @@ export interface AdapterStatus {
lastErrorAt?: number;
}
export interface AccountDatabaseMigration {
phase: 'preparing' | 'migrating' | 'complete' | 'failed';
usable: boolean;
processed: number;
total: number | null;
progress: number | null;
estimatedRemainingSeconds: number | null;
error?: string;
}
export interface AccountConnections {
uin: string;
nickname: string;
adapters: AdapterStatus[];
databaseMigration?: AccountDatabaseMigration;
}
export interface HookProcessInfo {