designtopack/src/stores/user.js
2024-11-18 13:45:40 +01:00

28 lines
783 B
JavaScript

import { defineStore } from "pinia";
import { ref, computed } from "vue";
export const useUserStore = defineStore("user", () => {
const user = ref(null);
const notifications = computed(() => {
return typeof user.value.notifications === "array"
? user.value.notifications
: Object.values(user.value.notifications);
});
function readNotification(notificationId) {
user.value.notifications.forEach((notification) => {
if (notification.id === notificationId) {
notification.isRead = true;
}
});
}
function readAllNotifications(notificationId) {
user.value.notifications.forEach((notification) => {
notification.isRead = true;
});
}
return { user, notifications, readNotification, readAllNotifications };
});