diff options
| author | soryu <soryu@soryu.co> | 2026-02-13 20:35:22 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-13 20:35:22 +0000 |
| commit | ad5af0f7677c73fc159a3036b9479d1d847adf97 (patch) | |
| tree | 718633b10a12d1c36f51a903a1f4149c5c6677f7 /makima/frontend/src/hooks/useDirectives.ts | |
| parent | c19da4baf036a395c50dfbd19f6a1a91a69229a7 (diff) | |
| download | soryu-ad5af0f7677c73fc159a3036b9479d1d847adf97.tar.gz soryu-ad5af0f7677c73fc159a3036b9479d1d847adf97.zip | |
Directive page improvements
Diffstat (limited to 'makima/frontend/src/hooks/useDirectives.ts')
| -rw-r--r-- | makima/frontend/src/hooks/useDirectives.ts | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/makima/frontend/src/hooks/useDirectives.ts b/makima/frontend/src/hooks/useDirectives.ts index e67733c..0453d14 100644 --- a/makima/frontend/src/hooks/useDirectives.ts +++ b/makima/frontend/src/hooks/useDirectives.ts @@ -63,6 +63,19 @@ export function useDirective(id: string | undefined) { const [loading, setLoading] = useState(true); const [error, setError] = useState<string | null>(null); + // Silently refresh without setting loading state (for polls) + const silentRefresh = useCallback(async () => { + if (!id) return; + try { + const d = await getDirective(id); + setDirective(d); + setError(null); + } catch (e) { + // Don't overwrite existing data on poll failure + } + }, [id]); + + // Full refresh with loading state (for initial load / explicit refresh) const refresh = useCallback(async () => { if (!id) return; try { @@ -77,9 +90,13 @@ export function useDirective(id: string | undefined) { } }, [id]); + // Reset state and fetch when ID changes useEffect(() => { + setDirective(null); + setError(null); + setLoading(true); refresh(); - }, [refresh]); + }, [id]); // eslint-disable-line react-hooks/exhaustive-deps // Auto-poll while directive is active, has an orchestrator task, or has a completion task useEffect(() => { @@ -90,9 +107,9 @@ export function useDirective(id: string | undefined) { directive.completionTaskId != null; if (!needsPolling) return; - const interval = setInterval(refresh, 5000); + const interval = setInterval(silentRefresh, 5000); return () => clearInterval(interval); - }, [directive?.status, directive?.orchestratorTaskId, directive?.completionTaskId, refresh]); + }, [directive?.status, directive?.orchestratorTaskId, directive?.completionTaskId, silentRefresh]); const update = useCallback(async (req: UpdateDirectiveRequest) => { if (!id) return; |
