Skip to content

Commit 5dc2a0c

Browse files
committed
fix(app2): explorer stats load
1 parent c1efbe7 commit 5dc2a0c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

app2/src/lib/components/model/StatisticComponent.svelte

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@ import Card from "$lib/components/ui/Card.svelte"
33
import Label from "$lib/components/ui/Label.svelte"
44
import type { StatisticItem } from "$lib/schema/statistics"
55
import NumberFlow from "@number-flow/svelte"
6+
import { onMount } from "svelte"
67
78
type Props = {
89
statistic: StatisticItem
910
class?: string
1011
}
1112
1213
const { statistic, class: className = "" }: Props = $props()
14+
let displayValue = $state(0)
15+
let isFirstLoad = $state(true)
16+
17+
// Update displayValue whenever statistic.value changes
18+
$effect(() => {
19+
if (isFirstLoad) {
20+
// On first load, animate from 0 to the value
21+
onMount(() => {
22+
displayValue = 0
23+
setTimeout(() => {
24+
displayValue = statistic.value
25+
isFirstLoad = false
26+
}, 300) // Small delay to sync with card fade-in
27+
})
28+
} else {
29+
// For subsequent updates, directly update the value
30+
displayValue = statistic.value
31+
}
32+
})
1333
1434
// Mapping of statistic names to display names
1535
const displayNames: Record<string, string> = {
@@ -35,6 +55,6 @@ function formatStatName(name: string): string {
3555
<Card class="h-22 transition-all hover:shadow-lg {className}">
3656
<Label>{formatStatName(statistic.name)}</Label>
3757
<p class="text-2xl font-bold mt-1">
38-
<NumberFlow value={statistic.value} />
58+
<NumberFlow value={displayValue} transformTiming={{duration:1500, easing: 'ease-out'}} opacityTiming={{duration:1500, easing: 'ease-out'}} spinTiming={{duration:1500, easing: 'ease-out'}} />
3959
</p>
4060
</Card>

0 commit comments

Comments
 (0)