setup stores and vitest

This commit is contained in:
Michael Dausmann
2023-11-28 00:28:19 +11:00
parent 7e46acf449
commit d8f20d9896
9 changed files with 1436 additions and 211 deletions

View File

@@ -1,4 +1,5 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
/*
This store manages User and Account state including the ActiveAccount
@@ -17,35 +18,33 @@ export enum NotificationType {
Error
}
interface State {
notifications: Notification[];
notificationsArchive: Notification[];
}
export const useNotifyStore = defineStore('notify', () => {
const notifications = ref<Notification[]>([]);
const notificationsArchive = ref<Notification[]>([]);
export const useNotifyStore = defineStore('notify', {
state: (): State => {
return {
notifications: [],
notificationsArchive: []
const notify = (messageOrError: unknown, type: NotificationType) => {
let message: string = '';
if (messageOrError instanceof Error) message = messageOrError.message;
if (typeof messageOrError === 'string') message = messageOrError;
const notification: Notification = {
message,
type,
notifyTime: Date.now()
};
},
actions: {
notify(messageOrError: unknown, type: NotificationType) {
let message: string = '';
if (messageOrError instanceof Error) message = messageOrError.message;
if (typeof messageOrError === 'string') message = messageOrError;
const notification: Notification = {
message,
type,
notifyTime: Date.now()
};
this.notifications.push(notification);
setTimeout(this.removeNotification.bind(this), 5000, notification);
},
removeNotification(notification: Notification) {
this.notifications = this.notifications.filter(
n => n.notifyTime != notification.notifyTime
);
}
}
notifications.value.push(notification);
setTimeout(removeNotification.bind(this), 5000, notification);
};
const removeNotification = (notification: Notification) => {
notifications.value = notifications.value.filter(
n => n.notifyTime != notification.notifyTime
);
};
return {
notifications,
notificationsArchive,
notify,
removeNotification
};
});