From edc17b8710fa18000429211f0956cac10a566893 Mon Sep 17 00:00:00 2001 From: nmemmert Date: Tue, 30 Jun 2026 12:01:09 -0400 Subject: [PATCH] Poll for new inbox messages every 30 seconds in admin Silently checks for new contact submissions in the background and prepends any new ones to the inbox without disrupting the current view. Co-Authored-By: Claude Sonnet 4.6 --- src/AdminPage.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/AdminPage.tsx b/src/AdminPage.tsx index 8434b85..0dcaba1 100644 --- a/src/AdminPage.tsx +++ b/src/AdminPage.tsx @@ -1427,6 +1427,24 @@ export default function AdminPage({ content, onSave, onLogout }: Props) { setContactStatus('ready') } + // Poll for new messages every 30 seconds — only prepend genuinely new ones + useEffect(() => { + const interval = setInterval(async () => { + try { + const r = await fetch('/api/admin-contact-submissions') + if (!r.ok) return + const data = await r.json() as { submissions?: ContactSubmission[] } + const fresh = Array.isArray(data.submissions) ? data.submissions : [] + setContactSubmissions(prev => { + const existingIds = new Set(prev.map(s => s.id)) + const newOnes = fresh.filter(s => !existingIds.has(s.id)) + return newOnes.length > 0 ? [...newOnes, ...prev] : prev + }) + } catch { /* silent — don't disrupt the UI */ } + }, 30_000) + return () => clearInterval(interval) + }, []) + useEffect(() => { const visible = contactSubmissions.filter(item => (emailMailboxView === 'archived' ? item.archived === true : item.archived !== true)) if (visible.length === 0) {