fix: render ready AI insights immediately
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
let sectionErrors = $state<Partial<Record<AIInsightSection, string>>>({});
|
||||
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 @@
|
||||
</script>
|
||||
|
||||
<section class="my-4" aria-label="تحلیل هوشمند" aria-busy={loading || refreshing}>
|
||||
{#if loading}
|
||||
{#if loading && !insight}
|
||||
<Card class="rounded-lg"
|
||||
><CardContent class="space-y-3 p-5" role="status" aria-label="در حال دریافت تحلیل هوشمند"
|
||||
><Skeleton class="h-6 w-44" /><Skeleton class="h-20 w-full" /></CardContent
|
||||
|
||||
Reference in New Issue
Block a user