diff --git a/src/lib/components/AIInsightPanel.svelte b/src/lib/components/AIInsightPanel.svelte index 5034eee..a11b456 100644 --- a/src/lib/components/AIInsightPanel.svelte +++ b/src/lib/components/AIInsightPanel.svelte @@ -28,6 +28,7 @@ let sectionErrors = $state>>({}); let error = $state(''); let sequence = 0; + let activeScope = ''; const confidenceLabel = $derived( ( @@ -49,7 +50,10 @@ error = ''; try { const next = await api.latestAIInsight(requestedModule, requestedTerminalId, requestedPeriodId); - if (current === sequence) insight = next; + if (current === sequence) { + insight = next; + loading = false; + } } catch (cause) { if (current !== sequence) return; error = @@ -128,6 +132,9 @@ const requestedModule = module; const requestedTerminalId = terminalId; const requestedPeriodId = periodId; + const scope = `${requestedModule}\u0000${requestedTerminalId ?? ''}\u0000${requestedPeriodId ?? ''}`; + if (scope === activeScope) return; + activeScope = scope; insight = null; loading = true; void load(requestedModule, requestedTerminalId, requestedPeriodId); @@ -141,7 +148,7 @@
- {#if loading} + {#if loading && !insight}