Currently, I am calling an API and receiving a list of results. These results are then processed into an object for iteration and display.
Below is the function responsible for this process:
var getAvailability = () => {
if (chosenData.hotel == "") {
showError("Please select a location before booking.");
$timeout(() => LTBNavService.setTab('location'), 50);
return;
}
searchResponse = {};
console.log(searchResponse);
WebAPI.getHotelAvailability(genSearchObject()).then((data) => {
searchResponse = data;
$timeout(() => $('[data-tab-content] .search-btn').first().focus(), 50);
generateRoomTypeObject(searchResponse);
}, (data) => searchResponse.error = data.data.errors[0].error);
};
The Issue: The previous results remain visible until the new results are loaded, causing an unwanted flicker and delay in user experience.
The proposed solution (requiring assistance): What would be the most effective method to address this issue? Ideally, I aim to clear or reset the search response to display only the newest set of results. Is it feasible to achieve this within the getAvailability function?
How can this best be achieved?