2022-08-25 23:04:23 -07:00
|
|
|
import { writable } from 'svelte/store';
|
|
|
|
|
|
|
|
|
|
export enum NotificationType {
|
|
|
|
|
Info = 'Info',
|
|
|
|
|
Error = 'Error'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class ImmichNotification {
|
|
|
|
|
id = new Date().getTime();
|
|
|
|
|
type!: NotificationType;
|
|
|
|
|
message!: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createNotificationList() {
|
2022-08-26 09:36:54 -07:00
|
|
|
const notificationList = writable<ImmichNotification[]>([]);
|
2022-08-25 23:04:23 -07:00
|
|
|
|
|
|
|
|
const show = ({ message = '', type = NotificationType.Info }) => {
|
|
|
|
|
const notification = new ImmichNotification();
|
|
|
|
|
notification.message = message;
|
|
|
|
|
notification.type = type;
|
|
|
|
|
|
2022-08-26 09:36:54 -07:00
|
|
|
notificationList.update((currentList) => [...currentList, notification]);
|
2022-08-25 23:04:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const removeNotificationById = (id: number) => {
|
2022-08-26 09:36:54 -07:00
|
|
|
notificationList.update((currentList) => currentList.filter((n) => n.id != id));
|
2022-08-25 23:04:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
show,
|
|
|
|
|
removeNotificationById,
|
2022-08-26 09:36:54 -07:00
|
|
|
notificationList
|
2022-08-25 23:04:23 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 09:36:54 -07:00
|
|
|
export const notificationController = createNotificationList();
|