update
This commit is contained in:
30
components/providers/download-dialog-store.ts
Normal file
30
components/providers/download-dialog-store.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
type DownloadDialogState = {
|
||||
isOpen: boolean;
|
||||
url: string | null;
|
||||
};
|
||||
|
||||
let state: DownloadDialogState = { isOpen: false, url: null };
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
function emit() {
|
||||
listeners.forEach((l) => l());
|
||||
}
|
||||
|
||||
export function subscribeDownloadDialog(listener: () => void) {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
|
||||
export function getDownloadDialogState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
export function openDownloadDialog(url: string | null) {
|
||||
state = { isOpen: true, url };
|
||||
emit();
|
||||
}
|
||||
|
||||
export function closeDownloadDialog() {
|
||||
state = { isOpen: false, url: null };
|
||||
emit();
|
||||
}
|
||||
Reference in New Issue
Block a user