@@ -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)
@@ -317,6 +324,7 @@ export const GlobalStateProvider = ({
317
324
useState < Item [ ] > ( [ ] ) ;
318
325
const claimSubscription = useSubscription ( gqlOnClaimItem , {
319
326
onSubscriptionData : ( { subscriptionData } ) => {
327
+ setTotalItemsReceivedViaSubscription ( ( prev ) => prev + 1 ) ;
320
328
const { updatedItem, newItem } : Claimed =
321
329
subscriptionData . data . onClaimItem ;
322
330
const pinboardId = updatedItem . pinboardId ;
@@ -330,11 +338,6 @@ export const GlobalStateProvider = ({
330
338
updatedItem ,
331
339
newItem ,
332
340
] ) ;
333
- if ( ! isExpanded && pinboardId !== selectedPinboardId ) {
334
- // TODO check this condition doesn't need to be ORed
335
- showNotification ( newItem ) ;
336
- setUnreadFlag ( pinboardId ) ( true ) ;
337
- }
338
341
}
339
342
} ,
340
343
} ) ;
@@ -681,9 +684,10 @@ export const GlobalStateProvider = ({
681
684
activePinboards,
682
685
activePinboardIds,
683
686
684
- allSubscriptionItems : allSubscriptionItems ,
685
- allSubscriptionClaimedItems : allSubscriptionClaimedItems ,
686
- allSubscriptionOnSeenItems : allSubscriptionOnSeenItems ,
687
+ allSubscriptionItems,
688
+ allSubscriptionClaimedItems,
689
+ allSubscriptionOnSeenItems,
690
+ totalItemsReceivedViaSubscription,
687
691
688
692
payloadToBeSent,
689
693
setPayloadToBeSent,
0 commit comments