aboutsummaryrefslogtreecommitdiff
path: root/loading/progress.ts
blob: f631757fd51c692ebf982c7129cc65dcd67708ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { writable, type Writable } from 'svelte/store'

/**
 * Phase the loading pipeline is in.
 *   `idle`      nothing running yet; percentage is 0.
 *   `loading`   a load is in flight; percentage advances 0 → 1.
 *   `complete`  load finished; percentage is 1.
 */
export type LoadingPhase = 'idle' | 'loading' | 'complete'

/** Reactive snapshot of the loading pipeline. */
export interface LoadingProgress {
  readonly percentage: number
  readonly currentMessage: string
  readonly phase: LoadingPhase
}

const DEFAULT: LoadingProgress = {
  percentage: 0,
  currentMessage: 'Preparing your reading space',
  phase: 'idle'
}

/** Global store of the initial-load progress. Components subscribe via `$`. */
export const loadingProgress: Writable<LoadingProgress> = writable(DEFAULT)

/** Reset the store to its initial state. Useful between sessions in dev. */
export function resetLoadingProgress(): void {
  loadingProgress.set(DEFAULT)
}