Skip to content

Commit 4a5c717

Browse files
committed
replace polling call for item counts and group pinboards, to instead be triggered whenever we hear about a new/mutated item on any pinboard
1 parent 8b02eae commit 4a5c717

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

client/src/fronts/frontsIntegration.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const FrontsIntegration = ({
4040
[frontsPinboardElements]
4141
);
4242

43-
const { setError } = useGlobalStateContext();
43+
const { setError, totalItemsReceivedViaSubscription } =
44+
useGlobalStateContext();
4445

4546
const apolloClient = useApolloClient();
4647

@@ -84,9 +85,12 @@ export const FrontsIntegration = ({
8485
variables: {
8586
pinboardIds,
8687
},
87-
pollInterval: 10_000, //TODO consider subscribing to all messages and fetching counts based on that, might be more efficient
8888
});
8989

90+
useEffect(() => {
91+
itemCountsQuery.refetch();
92+
}, [totalItemsReceivedViaSubscription]);
93+
9094
useEffect(() => {
9195
itemCountsQuery.data?.getItemCounts &&
9296
setMaybeItemCountsLookup(

client/src/globalState.tsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ interface GlobalStateContextShape {
6767
allSubscriptionItems: Item[];
6868
allSubscriptionClaimedItems: Item[]; // both the updated 'claimed' item and the new 'claim' item
6969
allSubscriptionOnSeenItems: LastItemSeenByUser[];
70+
totalItemsReceivedViaSubscription: number;
7071

7172
payloadToBeSent: PayloadAndType | null;
7273
setPayloadToBeSent: (newPayloadToBeSent: PayloadAndType | null) => void;
@@ -288,9 +289,15 @@ export const GlobalStateProvider = ({
288289
? [demoPinboardData]
289290
: pinboardDataQuery.data?.getPinboardsByIds || [];
290291

292+
const [
293+
totalItemsReceivedViaSubscription,
294+
setTotalItemsReceivedViaSubscription,
295+
] = useState(0);
296+
291297
const [allSubscriptionItems, setAllSubscriptionItems] = useState<Item[]>([]);
292298
const itemSubscription = useSubscription(gqlOnMutateItem, {
293299
onSubscriptionData: ({ subscriptionData }) => {
300+
setTotalItemsReceivedViaSubscription((prev) => prev + 1);
294301
const itemFromSubscription: Item = subscriptionData.data.onMutateItem;
295302
const pinboardId = itemFromSubscription.pinboardId;
296303
// TODO trigger any item count re-fetches (probably need to store a count of items to trigger useEffect elsewhere)
@@ -317,6 +324,7 @@ export const GlobalStateProvider = ({
317324
useState<Item[]>([]);
318325
const claimSubscription = useSubscription(gqlOnClaimItem, {
319326
onSubscriptionData: ({ subscriptionData }) => {
327+
setTotalItemsReceivedViaSubscription((prev) => prev + 1);
320328
const { updatedItem, newItem }: Claimed =
321329
subscriptionData.data.onClaimItem;
322330
const pinboardId = updatedItem.pinboardId;
@@ -330,11 +338,6 @@ export const GlobalStateProvider = ({
330338
updatedItem,
331339
newItem,
332340
]);
333-
if (!isExpanded && pinboardId !== selectedPinboardId) {
334-
// TODO check this condition doesn't need to be ORed
335-
showNotification(newItem);
336-
setUnreadFlag(pinboardId)(true);
337-
}
338341
}
339342
},
340343
});
@@ -681,9 +684,10 @@ export const GlobalStateProvider = ({
681684
activePinboards,
682685
activePinboardIds,
683686

684-
allSubscriptionItems: allSubscriptionItems,
685-
allSubscriptionClaimedItems: allSubscriptionClaimedItems,
686-
allSubscriptionOnSeenItems: allSubscriptionOnSeenItems,
687+
allSubscriptionItems,
688+
allSubscriptionClaimedItems,
689+
allSubscriptionOnSeenItems,
690+
totalItemsReceivedViaSubscription,
687691

688692
payloadToBeSent,
689693
setPayloadToBeSent,

client/src/inline/inlineMode.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, { useEffect, useMemo, useState } from "react";
22
import { InlineModePinboardTogglePortal } from "./inlineModePinboardToggle";
33
import { useLazyQuery } from "@apollo/client";
44
import { gqlGetItemCounts } from "../../gql";
5-
import { PinboardIdWithItemCounts } from "../../../shared/graphql/graphql";
5+
import { PinboardIdWithItemCounts } from "shared/graphql/graphql";
66
import { InlineModePanel } from "./inlineModePanel";
77
import ReactDOM from "react-dom";
88
import { InlineModeWorkflowColumnHeading } from "./inlineModeWorkflowColumnHeading";
9+
import { useGlobalStateContext } from "../globalState";
910

1011
export const WORKFLOW_PINBOARD_ELEMENTS_QUERY_SELECTOR =
1112
".content-list-item__field--pinboard";
@@ -37,6 +38,8 @@ export const InlineMode = ({
3738
maybeInlineSelectedPinboardId,
3839
setMaybeInlineSelectedPinboardId,
3940
}: InlineModeProps) => {
41+
const { totalItemsReceivedViaSubscription } = useGlobalStateContext();
42+
4043
const pinboardArea = useMemo(
4144
() => document.getElementById("pinboard-area"),
4245
[]
@@ -55,11 +58,9 @@ export const InlineMode = ({
5558
Record<string, PinboardIdWithItemCounts>
5659
>({});
5760

58-
const [fetchItemCounts, { stopPolling, startPolling }] =
59-
useLazyQuery(gqlGetItemCounts);
61+
const [fetchItemCounts] = useLazyQuery(gqlGetItemCounts);
6062

6163
useEffect(() => {
62-
stopPolling();
6364
const pinboardIds = Object.keys(workflowTitleElementLookup);
6465
if (pinboardIds.length > 0) {
6566
fetchItemCounts({
@@ -80,9 +81,8 @@ export const InlineMode = ({
8081
)
8182
),
8283
});
83-
startPolling(15000);
8484
}
85-
}, [workflowTitleElementLookup]);
85+
}, [workflowTitleElementLookup, totalItemsReceivedViaSubscription]);
8686

8787
const maybeSelectedNode =
8888
maybeInlineSelectedPinboardId &&

client/src/panel.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const Panel = ({
6767
setActiveTab,
6868
boundedPositionTranslation,
6969
setUnreadFlag,
70+
totalItemsReceivedViaSubscription,
7071
} = useGlobalStateContext();
7172

7273
const tourProgress = useTourProgress();
@@ -94,9 +95,11 @@ export const Panel = ({
9495
const isTopHalf =
9596
Math.abs(boundedPositionTranslation.y) > window.innerHeight / 2;
9697

97-
const groupPinboardIdsQuery = useQuery(gqlGetGroupPinboardIds, {
98-
pollInterval: 15000, // always poll this one, to ensure we get unread flags even when pinboard is not expanded
99-
});
98+
const groupPinboardIdsQuery = useQuery(gqlGetGroupPinboardIds);
99+
100+
useEffect(() => {
101+
groupPinboardIdsQuery.refetch();
102+
}, [totalItemsReceivedViaSubscription]);
100103

101104
const groupPinboardIdsWithClaimCounts: PinboardIdWithClaimCounts[] = useMemo(
102105
() =>

0 commit comments

Comments
 (0)