34 lines
883 B
TypeScript
34 lines
883 B
TypeScript
/**
|
|
* Global sync progress manager
|
|
* Stores sync progress state that can be accessed from any component
|
|
*/
|
|
|
|
import type { SyncProgress } from './userContentSync'
|
|
|
|
type SyncProgressListener = (progress: SyncProgress | null) => void
|
|
|
|
class SyncProgressManager {
|
|
private progress: SyncProgress | null = null
|
|
private listeners: Set<SyncProgressListener> = new Set()
|
|
|
|
setProgress(progress: SyncProgress | null): void {
|
|
this.progress = progress
|
|
this.listeners.forEach((listener) => listener(progress))
|
|
}
|
|
|
|
getProgress(): SyncProgress | null {
|
|
return this.progress
|
|
}
|
|
|
|
subscribe(listener: SyncProgressListener): () => void {
|
|
this.listeners.add(listener)
|
|
// Immediately call with current progress
|
|
listener(this.progress)
|
|
return () => {
|
|
this.listeners.delete(listener)
|
|
}
|
|
}
|
|
}
|
|
|
|
export const syncProgressManager = new SyncProgressManager()
|