@@ -67,6 +67,7 @@ interface GlobalStateContextShape {
67
67
allSubscriptionItems : Item [ ] ;
68
68
allSubscriptionClaimedItems : Item [ ] ; // both the updated 'claimed' item and the new 'claim' item
69
69
allSubscriptionOnSeenItems : LastItemSeenByUser [ ] ;
70
+ totalItemsReceivedViaSubscription : number ;
70
71
71
72
payloadToBeSent : PayloadAndType | null ;
72
73
setPayloadToBeSent : ( newPayloadToBeSent : PayloadAndType | null ) => void ;
@@ -288,9 +289,15 @@ export const GlobalStateProvider = ({
288
289
? [ demoPinboardData ]
289
290
: pinboardDataQuery . data ?. getPinboardsByIds || [ ] ;
290
291
292
+ const [
293
+ totalItemsReceivedViaSubscription ,
294
+ setTotalItemsReceivedViaSubscription ,
295
+ ] = useState ( 0 ) ;
296
+
291
297
const [ allSubscriptionItems , setAllSubscriptionItems ] = useState < Item [ ] > ( [ ] ) ;
292
298
const itemSubscription = useSubscription ( gqlOnMutateItem , {
293
299
onSubscriptionData : ( { subscriptionData } ) => {
300
+ setTotalItemsReceivedViaSubscription ( ( prev ) => prev + 1 ) ;
294
301
const itemFromSubscription : Item = subscriptionData . data . onMutateItem ;
295
302
const pinboardId = itemFromSubscription . pinboardId ;
296
303
// TODO trigger any item count re-fetches (probably need to store a count of items to trigger useEffect elsewhere)
@@ -319,6 +326,7 @@ export const GlobalStateProvider = ({
319
326
useState < Item [ ] > ( [ ] ) ;
320
327
const claimSubscription = useSubscription ( gqlOnClaimItem , {
321
328
onSubscriptionData : ( { subscriptionData } ) => {
329
+ setTotalItemsReceivedViaSubscription ( ( prev ) => prev + 1 ) ;
322
330
const { updatedItem, newItem } : Claimed =
323
331
subscriptionData . data . onClaimItem ;
324
332
const pinboardId = updatedItem . pinboardId ;
@@ -332,11 +340,6 @@ export const GlobalStateProvider = ({
332
340
updatedItem ,
333
341
newItem ,
334
342
] ) ;
335
- if ( ! isExpanded && pinboardId !== selectedPinboardId ) {
336
- // TODO check this condition doesn't need to be ORed
337
- showNotification ( newItem ) ;
338
- setUnreadFlag ( pinboardId ) ( true ) ;
339
- }
340
343
}
341
344
} ,
342
345
} ) ;
@@ -682,9 +685,10 @@ export const GlobalStateProvider = ({
682
685
activePinboards,
683
686
activePinboardIds,
684
687
685
- allSubscriptionItems : allSubscriptionItems ,
686
- allSubscriptionClaimedItems : allSubscriptionClaimedItems ,
687
- allSubscriptionOnSeenItems : allSubscriptionOnSeenItems ,
688
+ allSubscriptionItems,
689
+ allSubscriptionClaimedItems,
690
+ allSubscriptionOnSeenItems,
691
+ totalItemsReceivedViaSubscription,
688
692
689
693
payloadToBeSent,
690
694
setPayloadToBeSent,
0 commit comments