From 51329fb2e1b66231278e93605006a6f48c172ad8 Mon Sep 17 00:00:00 2001 From: rustmailer Date: Tue, 21 Apr 2026 20:44:08 +0800 Subject: [PATCH] Update index.tsx --- web/src/features/dashboard/index.tsx | 132 ++++++++++++++------------- 1 file changed, 68 insertions(+), 64 deletions(-) diff --git a/web/src/features/dashboard/index.tsx b/web/src/features/dashboard/index.tsx index 9c35dd8..4f71fe8 100644 --- a/web/src/features/dashboard/index.tsx +++ b/web/src/features/dashboard/index.tsx @@ -106,16 +106,20 @@ export default function MailArchiveDashboard() { queryKey: ['dashboard-stats'], enabled: !!token, queryFn: get_dashboard_stats, - initialData: INITIAL_DASHBOARD_STATS, + placeholderData: INITIAL_DASHBOARD_STATS, }); const navigate = useNavigate(); const { t, i18n } = useTranslation(); const currentLocale = i18n.resolvedLanguage || i18n.language || navigator.language; - const logicalSize = stats?.total_size_bytes ?? 0; - const blobSize = stats?.storage_usage_bytes ?? 0; - const indexSize = stats?.index_usage_bytes ?? 0; + + const stats1 = stats ?? INITIAL_DASHBOARD_STATS; + + + const logicalSize = stats1.total_size_bytes ?? 0; + const blobSize = stats1.storage_usage_bytes ?? 0; + const indexSize = stats1.index_usage_bytes ?? 0; const physicalTotal = blobSize + indexSize; const savingsPercent = logicalSize > 0 @@ -125,13 +129,13 @@ export default function MailArchiveDashboard() { const blobWidth = logicalSize > 0 ? (blobSize / logicalSize) * 100 : 0; const indexWidth = logicalSize > 0 ? (indexSize / logicalSize) * 100 : 0; - const totalAttachments = (stats?.with_attachment_count ?? 0) + (stats?.without_attachment_count ?? 0); - const attachmentRatio = totalAttachments > 0 ? (stats?.with_attachment_count ?? 0) / totalAttachments : 0; + const totalAttachments = (stats1.with_attachment_count ?? 0) + (stats1.without_attachment_count ?? 0); + const attachmentRatio = totalAttachments > 0 ? (stats1.with_attachment_count ?? 0) / totalAttachments : 0; - const hasRecentActivity = stats?.recent_activity && stats.recent_activity.length > 0; - const hasTopSenders = stats?.top_senders && stats.top_senders.length > 0; - const hasTopEmails = stats?.top_largest_emails && stats.top_largest_emails.length > 0; - const hasTopAccounts = stats?.top_accounts && stats.top_accounts.length > 0; + const hasRecentActivity = stats1.recent_activity && stats1.recent_activity.length > 0; + const hasTopSenders = stats1.top_senders && stats1.top_senders.length > 0; + const hasTopEmails = stats1.top_largest_emails && stats1.top_largest_emails.length > 0; + const hasTopAccounts = stats1.top_accounts && stats1.top_accounts.length > 0; const { minimalList } = useMinimalAccountList(); const getAccountIdByEmail = (email: string): number | null => { @@ -200,7 +204,7 @@ export default function MailArchiveDashboard() { -
{formatNumber(stats!.account_count)}
+
{formatNumber(stats1.account_count)}

{t('dashboard.connected')}

@@ -211,7 +215,7 @@ export default function MailArchiveDashboard() { -
{formatNumber(stats!.email_count)}
+
{formatNumber(stats1.email_count)}

{t('dashboard.syncedLocally')}

@@ -221,15 +225,15 @@ export default function MailArchiveDashboard() {
- {stats!.system_version ? ( - - {stats!.system_version} + {stats1.system_version ? ( + + {stats1.system_version} ) : 'N/A'}
-

{stats!.commit_hash?.substring(0, 7) ?? 'N/A'}

+

{stats1.commit_hash?.substring(0, 7) ?? 'N/A'}

@@ -288,7 +292,7 @@ export default function MailArchiveDashboard() { {hasRecentActivity ? ( - + @@ -377,7 +381,7 @@ export default function MailArchiveDashboard() { - {stats!.top_senders.map((s) => ( + {stats1.top_senders.map((s) => (
@@ -422,7 +426,7 @@ export default function MailArchiveDashboard() { - {stats!.top_largest_emails.map((m, i) => ( + {stats1.top_largest_emails.map((m, i) => (
@@ -453,51 +457,6 @@ export default function MailArchiveDashboard() { )} - - - {t('dashboard.top10Accounts')} - - - {hasTopAccounts ? ( - - - - {t('dashboard.account')} - {t('dashboard.emails')} - - - - {stats!.top_accounts.map((acc) => ( - - -
-
-
- - - -
-
- - {formatNumber(acc.count)} - - ))} - -
- ) : ( - - )} -
-
@@ -550,6 +509,51 @@ export default function MailArchiveDashboard() { )} + + + {t('dashboard.top10Accounts')} + + + {hasTopAccounts ? ( + + + + {t('dashboard.account')} + {t('dashboard.emails')} + + + + {stats1.top_accounts.map((acc) => ( + + +
+
+
+ + + +
+
+ + {formatNumber(acc.count)} + + ))} + +
+ ) : ( + + )} +
+