Skip to content

Commit

Permalink
trigger re-fetch of getItemCounts and getGroupPinboardIds wheneve…
Browse files Browse the repository at this point in the history
…r user receives any of their OWN `LastItemSeenByUser` via `onSeenItem` subscription, to ensure things viewed in one tab/tool are reflected in the counts in other tabs/tools
  • Loading branch information
twrichards committed Dec 5, 2024
1 parent 04596d2 commit f1ec7b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
12 changes: 9 additions & 3 deletions client/src/fronts/frontsIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ export const FrontsIntegration = ({
[frontsPinboardElements]
);

const { setError, totalItemsReceivedViaSubscription } =
useGlobalStateContext();
const {
setError,
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
} = useGlobalStateContext();

const apolloClient = useApolloClient();

Expand Down Expand Up @@ -79,7 +82,10 @@ export const FrontsIntegration = ({

useEffect(() => {
itemCountsQuery.refetch();
}, [totalItemsReceivedViaSubscription]);
}, [
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
]);

useEffect(() => {
itemCountsQuery.data?.getItemCounts &&
Expand Down
10 changes: 10 additions & 0 deletions client/src/globalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface GlobalStateContextShape {
allSubscriptionClaimedItems: Item[]; // both the updated 'claimed' item and the new 'claim' item
allSubscriptionOnSeenItems: LastItemSeenByUser[];
totalItemsReceivedViaSubscription: number;
totalOfMyOwnOnSeenItemsReceivedViaSubscription: number;

payloadToBeSent: PayloadAndType | null;
setPayloadToBeSent: (newPayloadToBeSent: PayloadAndType | null) => void;
Expand Down Expand Up @@ -341,6 +342,11 @@ export const GlobalStateProvider = ({
},
});

const [
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
setTotalOfMyOwnOnSeenItemsReceivedViaSubscription,
] = useState(0);

const [allSubscriptionOnSeenItems, setAllSubscriptionOnSeenItems] = useState<
LastItemSeenByUser[]
>([]);
Expand All @@ -359,6 +365,9 @@ export const GlobalStateProvider = ({
newLastItemSeenByUser,
]);
}
if (newLastItemSeenByUser.userEmail === userEmail) {
setTotalOfMyOwnOnSeenItemsReceivedViaSubscription((prev) => prev + 1);
}
},
});

Expand Down Expand Up @@ -688,6 +697,7 @@ export const GlobalStateProvider = ({
allSubscriptionClaimedItems,
allSubscriptionOnSeenItems,
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,

payloadToBeSent,
setPayloadToBeSent,
Expand Down
11 changes: 9 additions & 2 deletions client/src/inline/inlineMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export const InlineMode = ({
maybeInlineSelectedPinboardId,
setMaybeInlineSelectedPinboardId,
}: InlineModeProps) => {
const { totalItemsReceivedViaSubscription } = useGlobalStateContext();
const {
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
} = useGlobalStateContext();

const pinboardArea = useMemo(
() => document.getElementById("pinboard-area"),
Expand Down Expand Up @@ -82,7 +85,11 @@ export const InlineMode = ({
),
});
}
}, [workflowTitleElementLookup, totalItemsReceivedViaSubscription]);
}, [
workflowTitleElementLookup,
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
]);

const maybeSelectedNode =
maybeInlineSelectedPinboardId &&
Expand Down
6 changes: 5 additions & 1 deletion client/src/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const Panel = ({
unreadFlags,
setUnreadFlag,
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
} = useGlobalStateContext();

const tourProgress = useTourProgress();
Expand Down Expand Up @@ -100,7 +101,10 @@ export const Panel = ({

useEffect(() => {
groupPinboardIdsQuery.refetch();
}, [totalItemsReceivedViaSubscription]);
}, [
totalItemsReceivedViaSubscription,
totalOfMyOwnOnSeenItemsReceivedViaSubscription,
]);

const groupPinboardIdsWithClaimCounts: PinboardIdWithClaimCounts[] = useMemo(
() =>
Expand Down

0 comments on commit f1ec7b0

Please sign in to comment.