content notification read working
This commit is contained in:
parent
ffb8252808
commit
94c5737245
21 changed files with 317 additions and 163 deletions
45
src/stores/notifications.js
Normal file
45
src/stores/notifications.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { defineStore } from "pinia";
|
||||
import dayjs from "dayjs";
|
||||
import "dayjs/locale/fr";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useApiStore } from "./api";
|
||||
|
||||
export const useNotificationsStore = defineStore("notifications", () => {
|
||||
dayjs.locale("fr");
|
||||
|
||||
const router = useRouter();
|
||||
const api = useApiStore();
|
||||
|
||||
function formatDate(notification) {
|
||||
const notificationDigitalDate = parseInt(
|
||||
dayjs(notification.date).format("YYYYMMDD")
|
||||
);
|
||||
const todayDigitalDate = parseInt(dayjs().format("YYYYMMDD"));
|
||||
const isToday = notificationDigitalDate === todayDigitalDate;
|
||||
|
||||
if (isToday) {
|
||||
return dayjs(notification.date).format("HH:mm");
|
||||
} else if (todayDigitalDate === notificationDigitalDate + 1) {
|
||||
return "hier";
|
||||
} else {
|
||||
return dayjs(notification.date).format("DD MMM YY");
|
||||
}
|
||||
}
|
||||
|
||||
function read(notification) {
|
||||
if (!notification.id) {
|
||||
console.error(
|
||||
"Couldn't change notification status because it has no id."
|
||||
);
|
||||
} else if (notification.isread != true) {
|
||||
api
|
||||
.readNotification(notification.id)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
})
|
||||
.catch((err) => console.error("Notification could not be read.", err));
|
||||
}
|
||||
}
|
||||
|
||||
return { formatDate, read };
|
||||
});
|
||||
|
|
@ -13,14 +13,14 @@ export const useUserStore = defineStore("user", () => {
|
|||
function readNotification(notificationId) {
|
||||
user.value.notifications.forEach((notification) => {
|
||||
if (notification.id === notificationId) {
|
||||
notification.isRead = true;
|
||||
notification.isread = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function readAllNotifications(notificationId) {
|
||||
user.value.notifications.forEach((notification) => {
|
||||
notification.isRead = true;
|
||||
notification.isread = true;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue