@@ -173,38 +173,45 @@ export const AppealsProvider: React.FC<AppealsContextProps> = ({
173173 } ,
174174 skip : ! accountListId ,
175175 } ) ;
176- const { data } = contactsQueryResult ;
177176
178177 //#region Mass Actions
179178
180- const contactCount = data ?. contacts . totalCount ?? 0 ;
181- const { data : allContacts } = useGetIdsForMassSelectionQuery ( {
182- variables : {
183- accountListId,
184- first : contactCount ,
185- contactsFilters,
186- } ,
187- skip : contactCount === 0 ,
188- } ) ;
179+ const { data : allContacts , previousData : allContactsPrevious } =
180+ useGetIdsForMassSelectionQuery ( {
181+ variables : {
182+ accountListId,
183+ contactsFilters,
184+ } ,
185+ } ) ;
189186 // In the flows view, we need the total count of all contacts in every column, but the API
190187 // filters out contacts excluded from an appeal. We have to load excluded contacts also and
191188 // manually merge them with the other contacts.
192- const { data : allExcludedContacts } = useGetIdsForMassSelectionQuery ( {
189+ const {
190+ data : allExcludedContacts ,
191+ previousData : allExcludedContactsPrevious ,
192+ } = useGetIdsForMassSelectionQuery ( {
193193 variables : {
194194 accountListId,
195- first : contactCount ,
196195 contactsFilters : { ...contactsFilters , appealStatus : 'excluded' } ,
197196 } ,
198197 // Skip this query when there is an appealStatus filter from the list view
199- skip : contactCount === 0 || ! ! contactsFilters . appealStatus ,
198+ skip : ! ! contactsFilters . appealStatus ,
200199 } ) ;
200+ // When the next batch of contact ids is loading, use the previous batch of contact ids in the
201+ // meantime to avoid throwing out the selected contact ids.
201202 const allContactIds = useMemo (
202203 ( ) =>
203204 [
204- ...( allContacts ?. contacts . nodes ?? [ ] ) ,
205- ...( allExcludedContacts ?. contacts . nodes ?? [ ] ) ,
205+ ...( ( allContacts ?? allContactsPrevious ) ?. contacts . nodes ?? [ ] ) ,
206+ ...( ( allExcludedContacts ?? allExcludedContactsPrevious ) ?. contacts
207+ . nodes ?? [ ] ) ,
206208 ] . map ( ( contact ) => contact . id ) ,
207- [ allContacts , allExcludedContacts ] ,
209+ [
210+ allContacts ,
211+ allContactsPrevious ,
212+ allExcludedContacts ,
213+ allExcludedContactsPrevious ,
214+ ] ,
208215 ) ;
209216
210217 const {
0 commit comments