fix: render ready AI insights immediately
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
let sectionErrors = $state<Partial<Record<AIInsightSection, string>>>({});
|
let sectionErrors = $state<Partial<Record<AIInsightSection, string>>>({});
|
||||||
let error = $state('');
|
let error = $state('');
|
||||||
let sequence = 0;
|
let sequence = 0;
|
||||||
|
let activeScope = '';
|
||||||
|
|
||||||
const confidenceLabel = $derived(
|
const confidenceLabel = $derived(
|
||||||
(
|
(
|
||||||
@@ -49,7 +50,10 @@
|
|||||||
error = '';
|
error = '';
|
||||||
try {
|
try {
|
||||||
const next = await api.latestAIInsight(requestedModule, requestedTerminalId, requestedPeriodId);
|
const next = await api.latestAIInsight(requestedModule, requestedTerminalId, requestedPeriodId);
|
||||||
if (current === sequence) insight = next;
|
if (current === sequence) {
|
||||||
|
insight = next;
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
} catch (cause) {
|
} catch (cause) {
|
||||||
if (current !== sequence) return;
|
if (current !== sequence) return;
|
||||||
error =
|
error =
|
||||||
@@ -128,6 +132,9 @@
|
|||||||
const requestedModule = module;
|
const requestedModule = module;
|
||||||
const requestedTerminalId = terminalId;
|
const requestedTerminalId = terminalId;
|
||||||
const requestedPeriodId = periodId;
|
const requestedPeriodId = periodId;
|
||||||
|
const scope = `${requestedModule}\u0000${requestedTerminalId ?? ''}\u0000${requestedPeriodId ?? ''}`;
|
||||||
|
if (scope === activeScope) return;
|
||||||
|
activeScope = scope;
|
||||||
insight = null;
|
insight = null;
|
||||||
loading = true;
|
loading = true;
|
||||||
void load(requestedModule, requestedTerminalId, requestedPeriodId);
|
void load(requestedModule, requestedTerminalId, requestedPeriodId);
|
||||||
@@ -141,7 +148,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section class="my-4" aria-label="تحلیل هوشمند" aria-busy={loading || refreshing}>
|
<section class="my-4" aria-label="تحلیل هوشمند" aria-busy={loading || refreshing}>
|
||||||
{#if loading}
|
{#if loading && !insight}
|
||||||
<Card class="rounded-lg"
|
<Card class="rounded-lg"
|
||||||
><CardContent class="space-y-3 p-5" role="status" aria-label="در حال دریافت تحلیل هوشمند"
|
><CardContent class="space-y-3 p-5" role="status" aria-label="در حال دریافت تحلیل هوشمند"
|
||||||
><Skeleton class="h-6 w-44" /><Skeleton class="h-20 w-full" /></CardContent
|
><Skeleton class="h-6 w-44" /><Skeleton class="h-20 w-full" /></CardContent
|
||||||
|
|||||||
Reference in New Issue
Block a user