From 23655004db15f6c1cd6cd31258253e1dcf3944b2 Mon Sep 17 00:00:00 2001 From: Tom Richards Date: Mon, 2 Dec 2024 23:36:19 +0000 Subject: [PATCH] address TODO around clearing unread flags when closing a 'my pinboard' which is also a group pinboard and might have its own unread there --- client/src/globalState.tsx | 3 +-- client/src/panel.tsx | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client/src/globalState.tsx b/client/src/globalState.tsx index 3d7f775d..92f862c0 100644 --- a/client/src/globalState.tsx +++ b/client/src/globalState.tsx @@ -566,8 +566,7 @@ export const GlobalStateProvider = ({ } setSelectedPinboardId(null); setError(pinboardIdToClose, undefined); - //TODO probably need to check if pinboard is also in group pinboards, so we don't lose an unread on there - setUnreadFlag(pinboardIdToClose)(undefined); + setUnreadFlag(pinboardIdToClose)(undefined); // note that panel.tsx detects this and reinstates any hasUnread from the group pinboards }; useEffect(() => { diff --git a/client/src/panel.tsx b/client/src/panel.tsx index 1af9c7ce..0f10beaf 100644 --- a/client/src/panel.tsx +++ b/client/src/panel.tsx @@ -66,6 +66,7 @@ export const Panel = ({ activeTab, setActiveTab, boundedPositionTranslation, + unreadFlags, setUnreadFlag, totalItemsReceivedViaSubscription, } = useGlobalStateContext(); @@ -109,6 +110,15 @@ export const Panel = ({ [groupPinboardIdsQuery.data] ); + useEffect(() => { + // ensure that if ever the pinboard is closed manually, the hasUnread from the group pinboards becomes the value + groupPinboardIdsWithClaimCounts.forEach( + ({ pinboardId, hasUnread }) => + unreadFlags[pinboardId] === undefined && + setUnreadFlag(pinboardId)(hasUnread) + ); + }, [unreadFlags]); + useEffect(() => { groupPinboardIdsWithClaimCounts.forEach(({ pinboardId, hasUnread }) => setUnreadFlag(pinboardId)(hasUnread)