diff --git a/frontend/src/app/terminal/watchlist/page.tsx b/frontend/src/app/terminal/watchlist/page.tsx index 007f533..214fe18 100755 --- a/frontend/src/app/terminal/watchlist/page.tsx +++ b/frontend/src/app/terminal/watchlist/page.tsx @@ -118,27 +118,38 @@ export default function WatchlistPage() { const handleAdd = useCallback(async (e: React.FormEvent) => { e.preventDefault() if (!newDomain.trim()) return + const domainName = newDomain.trim().toLowerCase() setAdding(true) try { - const result = await addDomain(newDomain.trim()) - showToast(`Added: ${newDomain.trim()}`, 'success') + await addDomain(domainName) + showToast(`Added: ${domainName}`, 'success') setNewDomain('') - - // Trigger health check for the newly added domain - if (result?.id) { - setLoadingHealth(prev => ({ ...prev, [result.id]: true })) - try { - const report = await api.getDomainHealth(result.id, { refresh: true }) - setHealthReports(prev => ({ ...prev, [result.id]: report })) - } catch {} - finally { setLoadingHealth(prev => ({ ...prev, [result.id]: false })) } - } } catch (err: any) { showToast(err.message || 'Failed', 'error') } finally { setAdding(false) } }, [newDomain, addDomain, showToast]) + + // Auto-trigger health check for newly added domains + useEffect(() => { + if (!domains?.length) return + + domains.forEach(domain => { + // If no health report exists and not currently loading, trigger check + if (!healthReports[domain.id] && !loadingHealth[domain.id]) { + setLoadingHealth(prev => ({ ...prev, [domain.id]: true })) + api.getDomainHealth(domain.id, { refresh: false }) + .then(report => { + setHealthReports(prev => ({ ...prev, [domain.id]: report })) + }) + .catch(() => {}) + .finally(() => { + setLoadingHealth(prev => ({ ...prev, [domain.id]: false })) + }) + } + }) + }, [domains]) const handleRefresh = useCallback(async (id: number) => { setRefreshingId(id)