feature/IO-3096-GlobalNotifications - Checkpoint

This commit is contained in:
Dave Richer
2025-02-25 20:02:27 -05:00
parent fa39e2b97e
commit 7f547c90c2

View File

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