feature/IO-3096-GlobalNotifications - Checkpoint
This commit is contained in:
@@ -32,9 +32,6 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
setError(err.message);
|
setError(err.message);
|
||||||
console.error("GET_NOTIFICATIONS error:", err);
|
console.error("GET_NOTIFICATIONS error:", err);
|
||||||
setTimeout(() => refetch(), 2000);
|
setTimeout(() => refetch(), 2000);
|
||||||
},
|
|
||||||
onCompleted: (data) => {
|
|
||||||
console.log("GET_NOTIFICATIONS completed:", data?.notifications);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -91,7 +88,6 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("Data changed:", data);
|
|
||||||
if (data?.notifications) {
|
if (data?.notifications) {
|
||||||
const processedNotifications = data.notifications
|
const processedNotifications = data.notifications
|
||||||
.map((notif) => {
|
.map((notif) => {
|
||||||
@@ -120,15 +116,11 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
read: notif.read,
|
read: notif.read,
|
||||||
__typename: notif.__typename
|
__typename: notif.__typename
|
||||||
};
|
};
|
||||||
console.log("Processed notification with RO:", processed);
|
|
||||||
return processed;
|
return processed;
|
||||||
})
|
})
|
||||||
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
|
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
|
||||||
console.log("Setting notifications with RO:", processedNotifications);
|
|
||||||
setNotifications(processedNotifications);
|
setNotifications(processedNotifications);
|
||||||
setError(null);
|
setError(null);
|
||||||
} else {
|
|
||||||
console.log("No notifications in data:", data);
|
|
||||||
}
|
}
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
@@ -138,18 +130,12 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
}
|
}
|
||||||
}, [queryError, mutationError]);
|
}, [queryError, mutationError]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.log("Notifications state updated:", notifications);
|
|
||||||
}, [notifications]);
|
|
||||||
|
|
||||||
const loadMore = useCallback(() => {
|
const loadMore = useCallback(() => {
|
||||||
if (!loading && data?.notifications.length) {
|
if (!loading && data?.notifications.length) {
|
||||||
console.log("Loading more notifications, current length:", data.notifications.length);
|
|
||||||
fetchMore({
|
fetchMore({
|
||||||
variables: { offset: data.notifications.length },
|
variables: { offset: data.notifications.length },
|
||||||
updateQuery: (prev, { fetchMoreResult }) => {
|
updateQuery: (prev, { fetchMoreResult }) => {
|
||||||
if (!fetchMoreResult) return prev;
|
if (!fetchMoreResult) return prev;
|
||||||
console.log("Fetched more:", fetchMoreResult.notifications);
|
|
||||||
return {
|
return {
|
||||||
notifications: [...prev.notifications, ...fetchMoreResult.notifications]
|
notifications: [...prev.notifications, ...fetchMoreResult.notifications]
|
||||||
};
|
};
|
||||||
@@ -163,11 +149,9 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
|
|
||||||
const handleToggleUnreadOnly = (value) => {
|
const handleToggleUnreadOnly = (value) => {
|
||||||
setShowUnreadOnly(value);
|
setShowUnreadOnly(value);
|
||||||
console.log("Toggled showUnreadOnly:", value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMarkAllRead = () => {
|
const handleMarkAllRead = () => {
|
||||||
console.log("Marking all notifications as read");
|
|
||||||
markAllReadMutation()
|
markAllReadMutation()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
@@ -175,20 +159,16 @@ export function NotificationCenterContainer({ visible, onClose, bodyshop }) {
|
|||||||
const updatedNotifications = prev.map((notif) =>
|
const updatedNotifications = prev.map((notif) =>
|
||||||
notif.read === null ? { ...notif, read: timestamp } : notif
|
notif.read === null ? { ...notif, read: timestamp } : notif
|
||||||
);
|
);
|
||||||
console.log("Updated notifications after mark all read:", updatedNotifications);
|
|
||||||
return [...updatedNotifications];
|
return [...updatedNotifications];
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((e) => console.error(`Error marking all notifications read: ${e?.message || ""}`));
|
.catch((e) => console.error(`Error marking all notifications read: ${e?.message || ""}`));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO Tinker
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible && !isConnected) {
|
if (visible && !isConnected) {
|
||||||
console.log("Notification Center opened, socket disconnected, refetching...");
|
|
||||||
refetch();
|
refetch();
|
||||||
} else if (visible && isConnected) {
|
|
||||||
console.log("Notification Center opened, socket connected, relying on cache...");
|
|
||||||
refetch(); // Ensure fresh data even with socket
|
|
||||||
}
|
}
|
||||||
}, [visible, isConnected, refetch]);
|
}, [visible, isConnected, refetch]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user