designtopack/src/stores/user.js

39 lines
918 B
JavaScript
Raw Normal View History

2024-09-10 12:09:53 +02:00
import { defineStore } from "pinia";
2024-10-30 10:56:11 +01:00
import { ref, computed } from "vue";
2024-09-10 12:09:53 +02:00
export const useUserStore = defineStore("user", () => {
const user = ref(null);
2024-10-30 10:56:11 +01:00
const notifications = computed(() => {
2024-11-13 07:46:32 +01:00
return typeof user.value.notifications === "array"
? user.value.notifications
: Object.values(user.value.notifications);
2024-10-30 10:56:11 +01:00
});
2024-11-18 09:36:15 +01:00
function readNotification(notificationId) {
user.value.notifications.forEach((notification) => {
if (notification.id === notificationId) {
notification.isread = "true";
2024-11-18 09:36:15 +01:00
}
});
}
function readAllNotifications(notificationId) {
user.value.notifications.forEach((notification) => {
2024-12-19 10:32:48 +01:00
notification.isread = true;
});
}
2025-01-07 11:33:15 +01:00
function canEditComment(comment) {
return user.value.uuid === comment.author.uuid;
}
return {
user,
notifications,
readNotification,
readAllNotifications,
canEditComment,
};
2024-09-10 12:09:53 +02:00
});