Skip to content

Commit

Permalink
Add async fix from Hayley
Browse files Browse the repository at this point in the history
Also fades the text in and out for your weighted hours.
  • Loading branch information
kitsuta committed Nov 8, 2024
1 parent c25fd45 commit a6a7f13
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions uber/templates/staffing/shifts.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ <h2 class="accordion-header" id="restricted-jobs-info-header">
if (json.success) {
$("#message-alert").addClass("alert-success").show().children('span').html(message);
shiftDetails.hide();
$("#weighted-hours").text(json.hours);
$("#weighted-hours").fadeOut(500).fadeIn(500);
$("#weighted-hours").fadeOut(function() {
$(this).text(json.hours)
}).fadeIn();
fetchedEventList.length = 0;
ec.refetchEvents();
} else {
Expand Down Expand Up @@ -278,6 +279,9 @@ <h2 class="accordion-header" id="restricted-jobs-info-header">
if (json.success) {
$("#message-alert").addClass("alert-success").show().children('span').html(message);
shiftDetails.hide();
$("#weighted-hours").fadeOut(function() {
$(this).text(json.hours)
}).fadeIn();
fetchedEventList.length = 0;
ec.refetchEvents();
} else {
Expand Down Expand Up @@ -357,31 +361,22 @@ <h2 class="accordion-header" id="restricted-jobs-info-header">
}
var possibleEventURLS = {'available': 'get_available_jobs', 'assigned': 'get_assigned_jobs'};
var fetchEventsURLS = ['get_available_jobs', 'get_assigned_jobs'];
var fetchedEventList = new Array();
let fetchEvents = function(fetchInfo, successCallback, failureCallback) {
if (fetchedEventList.length != 0) {
successCallback(fetchedEventList);
}
for (const url of fetchEventsURLS) {
$.ajax({
method: 'GET',
url: url,
dataType: 'json',
data: fetchEventsParams,
success: function (eventList) {
fetchedEventList.push(...eventList);
},
error: function () {}
});
}

console.log(fetchedEventList);
var fetchedEventList = [];

if (fetchedEventList.length != 0) {
successCallback(fetchedEventList);
} else {
failureCallback('Unable to connect to server, please try again.');
}
let fetchEvents = async function() {
if (fetchedEventList.length > 0) {
return fetchedEventList;
}
let eventParams = new URLSearchParams(fetchEventsParams);
try {
const responses = await Promise.all(fetchEventsURLS.map(url => fetch(url + "?" + eventParams)));
const eventLists = await Promise.all(responses.map((response) => response.json()));
let allNewEvents = [].concat(...eventLists);
fetchedEventList.push(...allNewEvents);
return fetchedEventList;
} catch (e) {
showErrorMessage('Unable to connect to server, please try again.')
}
}

let addEvents = function(id) {
Expand Down Expand Up @@ -427,7 +422,7 @@ <h2 class="accordion-header" id="restricted-jobs-info-header">
fetchEventsParams[key] = value;
}

if ('get_available_jobs' in fetchEventsURLS) {
if (fetchEventsURLS.includes('get_available_jobs')) {
fetchedEventList.length = 0;
ec.refetchEvents();
}
Expand Down

0 comments on commit a6a7f13

Please sign in to comment.