Fix health check auto-trigger
Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled

This commit is contained in:
2025-12-12 22:36:44 +01:00
parent 718a7d64e5
commit b820690478

View File

@ -118,21 +118,12 @@ 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 {
@ -140,6 +131,26 @@ export default function WatchlistPage() {
}
}, [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)
try {