aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/stores/notifs.js
blob: f117f18421fb4c0bb46baf8a32b976ff92f17fa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { writable } from "svelte/store";
import { nanoid } from 'nanoid'

export const notifs = writable([]);

export function notif(notification) {
    let _notif = {
        id: nanoid(),
        timeout: 10000,
        ...notification
    }
    notifs.update(_notifs => {
        setTimeout(() => {
            removeNotif(_notif.id)
        }, _notif.timeout);
        return [..._notifs, _notif];
    });
}

export function removeNotif(notifId) {
    notifs.update(_notifs => {
        return _notifs.filter(n => n.id !== notifId);
    });
}