Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: Fixed code logic to prevent facilities list from becoming empty if the infinite scroll call fails(#282) #283

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 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(payload.viewIndex && payload.viewIndex > 0) {
facilityList = facilities.concat(resp.data.docs)
} else {
facilityList = resp.data.docs
}
if(!hasError(resp) && resp.data.count > 0){
if(payload.viewIndex && payload.viewIndex > 0) {
facilities = facilities.concat(resp.data.docs)
} else {
facilities = resp.data.docs
}
total = resp.data.count
} else {
}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
Loading