@@ -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,12 +326,14 @@ 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 ;
325
333
if (
326
334
activePinboardIds . includes ( pinboardId ) ||
327
335
pinboardId === maybeInlineSelectedPinboardId
336
+ //FIXME make this also care about peeking
328
337
) {
329
338
addEmailsToLookup ( [ newItem . userEmail ] ) ;
330
339
setAllSubscriptionClaimedItems ( ( prevState ) => [
@@ -352,6 +361,7 @@ export const GlobalStateProvider = ({
352
361
if (
353
362
activePinboardIds . includes ( pinboardId ) ||
354
363
pinboardId === maybeInlineSelectedPinboardId
364
+ //FIXME make this also care about peeking
355
365
) {
356
366
addEmailsToLookup ( [ newLastItemSeenByUser . userEmail ] ) ;
357
367
setAllSubscriptionOnSeenItems ( ( prevState ) => [
@@ -682,9 +692,10 @@ export const GlobalStateProvider = ({
682
692
activePinboards,
683
693
activePinboardIds,
684
694
685
- allSubscriptionItems : allSubscriptionItems ,
686
- allSubscriptionClaimedItems : allSubscriptionClaimedItems ,
687
- allSubscriptionOnSeenItems : allSubscriptionOnSeenItems ,
695
+ allSubscriptionItems,
696
+ allSubscriptionClaimedItems,
697
+ allSubscriptionOnSeenItems,
698
+ totalItemsReceivedViaSubscription,
688
699
689
700
payloadToBeSent,
690
701
setPayloadToBeSent,
0 commit comments