mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Feat: Reworked ENTIRE Project for Readability
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
export interface Toast {
|
||||
id: string;
|
||||
kind: "success" | "error" | "info" | "download";
|
||||
title: string;
|
||||
body?: string;
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
export interface ActiveDownload {
|
||||
chapterId: number;
|
||||
mangaId: number;
|
||||
progress: number;
|
||||
}
|
||||
|
||||
class NotificationStore {
|
||||
toasts: Toast[] = $state([]);
|
||||
activeDownloads: ActiveDownload[] = $state([]);
|
||||
|
||||
addToast(toast: Omit<Toast, "id">) {
|
||||
this.toasts = [...this.toasts, { ...toast, id: Math.random().toString(36).slice(2) }].slice(-5);
|
||||
}
|
||||
|
||||
dismissToast(id: string) {
|
||||
this.toasts = this.toasts.filter(x => x.id !== id);
|
||||
}
|
||||
|
||||
setActiveDownloads(next: ActiveDownload[]) {
|
||||
this.activeDownloads = next;
|
||||
}
|
||||
}
|
||||
|
||||
export const notifications = new NotificationStore();
|
||||
|
||||
export function addToast(toast: Omit<Toast, "id">) { notifications.addToast(toast); }
|
||||
export function dismissToast(id: string) { notifications.dismissToast(id); }
|
||||
export function setActiveDownloads(next: ActiveDownload[]) { notifications.setActiveDownloads(next); }
|
||||
Reference in New Issue
Block a user