mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 12:33:03 +00:00
30 lines
659 B
TypeScript
30 lines
659 B
TypeScript
import { defineStore } from "pinia";
|
|
import { Notif } from "../interfaces";
|
|
import { NotifType } from "../composables/enums";
|
|
|
|
const useNotifStore = defineStore("notification", {
|
|
state: () => ({
|
|
notifs: <Notif[]>[],
|
|
}),
|
|
actions: {
|
|
showNotification(new_text: string, new_type?: NotifType) {
|
|
this.notifs.push(<Notif>{
|
|
text: new_text,
|
|
type: new_type,
|
|
});
|
|
|
|
setTimeout(() => {
|
|
this.notifs.shift();
|
|
}, 3000);
|
|
},
|
|
},
|
|
});
|
|
|
|
class Notification {
|
|
constructor(text: string, type?: NotifType) {
|
|
useNotifStore().showNotification(text, type);
|
|
}
|
|
}
|
|
|
|
export { useNotifStore, Notification, NotifType };
|