Skip to content

Commit

Permalink
Merge pull request #296 from ymaheshwari1/#282
Browse files Browse the repository at this point in the history
Improved: Fixed code logic to prevent facilities list from becoming empty if the infinite scroll call fails(#282)
  • Loading branch information
ymaheshwari1 authored Aug 13, 2024
2 parents d165dd0 + 5c83b05 commit 892233a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,31 @@ const actions: ActionTree<FacilityState, RootState> = {
...payload
}

const facilities = JSON.parse(JSON.stringify(state.facilities.list));
let total = 0, facilityList = [];
let facilities = JSON.parse(JSON.stringify(state.facilities.list));
let total = 0;

try {
const resp = await FacilityService.fetchFacilities(params)

if(!hasError(resp) && resp.data.count) {
if(!hasError(resp) && resp.data.count > 0) {
if(payload.viewIndex && payload.viewIndex > 0) {
facilityList = facilities.concat(resp.data.docs)
facilities = facilities.concat(resp.data.docs)
} else {
facilityList = resp.data.docs
facilities = resp.data.docs
}
total = resp.data.count
} else {
throw resp.data
}
} catch(error) {
logger.error(error)
if (payload.viewIndex === 0) {
facilities = [];
total = 0;
}
}

commit(types.FACILITY_LIST_UPDATED , { facilities, total });
emitter.emit("dismissLoader");
commit(types.FACILITY_LIST_UPDATED , { facilities: facilityList, total });

if(facilities.length) {
await dispatch('fetchFacilitiesAdditionalInformation', payload)
Expand Down

0 comments on commit 892233a

Please sign in to comment.