notification.ts 814 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { writable } from 'svelte/store';
  2. export enum NotificationType {
  3. Info = 'Info',
  4. Error = 'Error'
  5. }
  6. export class ImmichNotification {
  7. id = new Date().getTime();
  8. type!: NotificationType;
  9. message!: string;
  10. }
  11. function createNotificationList() {
  12. const { set, update, subscribe } = writable<ImmichNotification[]>([]);
  13. const show = ({ message = '', type = NotificationType.Info }) => {
  14. const notification = new ImmichNotification();
  15. notification.message = message;
  16. notification.type = type;
  17. update((currentList) => [...currentList, notification]);
  18. };
  19. const removeNotificationById = (id: number) => {
  20. update((currentList) => currentList.filter((n) => n.id != id));
  21. };
  22. return {
  23. show,
  24. removeNotificationById,
  25. subscribe
  26. };
  27. }
  28. export const notificationList = createNotificationList();