read all working

This commit is contained in:
isUnknown 2025-01-15 16:24:34 +01:00
parent 495e1c024e
commit ef09a04b5e
7 changed files with 105 additions and 65 deletions

View file

@ -151,7 +151,6 @@ async function read() {
comment.id,
page.value.uri
);
userStore.readNotification(comment.id, route.params.id);
} catch (error) {
console.log("Erreur lors de la lecture de la notification : ", error);
}

View file

@ -1,8 +1,9 @@
import { defineStore, storeToRefs } from "pinia";
import { usePageStore } from "./page.js";
import uniqid from "uniqid";
import { useUserStore } from "./user";
export const useApiStore = defineStore("api", () => {
const userStore = useUserStore();
async function fetchData(path = window.location.pathname) {
const isHomePage = path === "/";
path = path === "/" ? "/home" : path;
@ -166,6 +167,10 @@ export const useApiStore = defineStore("api", () => {
if (data.error) {
throw new Error(data);
} else {
if (!projectId.startsWith("/")) {
projectId = "/" + projectId;
}
userStore.readNotification(notificationId, projectId);
return data;
}
} catch (error) {
@ -208,7 +213,10 @@ export const useApiStore = defineStore("api", () => {
if (data.error) {
throw new Error(data);
} else {
console.log(data);
userStore.readAllNotifications();
console.log("All notifications read.");
return data;
}
} catch (error) {
throw error;

View file

@ -21,11 +21,12 @@ export const useUserStore = defineStore("user", () => {
});
});
function readNotification(notificationId, projectSlug) {
function readNotification(notificationId, projectId) {
console.log("Read notification", notificationId, projectId);
projects.value = projects.value.map((project) => ({
...project,
notifications:
project.slug === projectSlug
project.uuid === projectId || project.uri === projectId
? project.notifications.map((notification) =>
notification.id === notificationId
? {

View file

@ -117,7 +117,6 @@ function changeTab(newValue) {
function readAll() {
try {
api.readAllNotifications();
userStore.readAllNotifications();
} catch (error) {
console.log("Could not read all notifications : ", error);
}