@@ -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,17 +289,23 @@ 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)
297
304
if (
298
305
activePinboardIds . includes ( pinboardId ) ||
299
306
pinboardId === maybeInlineSelectedPinboardId
300
- ) {
301
307
//FIXME make this also care about peeking
308
+ ) {
302
309
addEmailsToLookup ( [ itemFromSubscription . userEmail ] ) ;
303
310
setAllSubscriptionItems ( ( prevState ) => [
304
311
...prevState ,
@@ -320,12 +327,14 @@ export const GlobalStateProvider = ({
320
327
useState < Item [ ] > ( [ ] ) ;
321
328
const claimSubscription = useSubscription ( gqlOnClaimItem , {
322
329
onSubscriptionData : ( { subscriptionData } ) => {
330
+ setTotalItemsReceivedViaSubscription ( ( prev ) => prev + 1 ) ;
323
331
const { updatedItem, newItem } : Claimed =
324
332
subscriptionData . data . onClaimItem ;
325
333
const pinboardId = updatedItem . pinboardId ;
326
334
if (
327
335
activePinboardIds . includes ( pinboardId ) ||
328
336
pinboardId === maybeInlineSelectedPinboardId
337
+ //FIXME make this also care about peeking
329
338
) {
330
339
addEmailsToLookup ( [ newItem . userEmail ] ) ;
331
340
setAllSubscriptionClaimedItems ( ( prevState ) => [
@@ -353,6 +362,7 @@ export const GlobalStateProvider = ({
353
362
if (
354
363
activePinboardIds . includes ( pinboardId ) ||
355
364
pinboardId === maybeInlineSelectedPinboardId
365
+ //FIXME make this also care about peeking
356
366
) {
357
367
addEmailsToLookup ( [ newLastItemSeenByUser . userEmail ] ) ;
358
368
setAllSubscriptionOnSeenItems ( ( prevState ) => [
@@ -683,9 +693,10 @@ export const GlobalStateProvider = ({
683
693
activePinboards,
684
694
activePinboardIds,
685
695
686
- allSubscriptionItems : allSubscriptionItems ,
687
- allSubscriptionClaimedItems : allSubscriptionClaimedItems ,
688
- allSubscriptionOnSeenItems : allSubscriptionOnSeenItems ,
696
+ allSubscriptionItems,
697
+ allSubscriptionClaimedItems,
698
+ allSubscriptionOnSeenItems,
699
+ totalItemsReceivedViaSubscription,
689
700
690
701
payloadToBeSent,
691
702
setPayloadToBeSent,
0 commit comments