[O] Optimize loadAssignments()

This commit is contained in:
Hykilpikonna
2019-09-07 14:07:49 -04:00
parent 5ac3183ec1
commit 1ca32b5ebd
+15 -26
View File
@@ -109,7 +109,8 @@ export default class App extends Vue
// Show error message TODO: Show it properly // Show error message TODO: Show it properly
alert(response.data); alert(response.data);
} }
}); })
.catch(alert);
} }
/** /**
@@ -123,34 +124,22 @@ export default class App extends Vue
this.courses.forEach(course => this.courses.forEach(course =>
{ {
// Send request to get assignments // Send request to get assignments
fetch(`${Constants.API_URL}/assignments`, this.http.post('/assignments', {id: course.assignmentsId}).then(response =>
{method: 'POST', body: JSON.stringify({token: this.token, id: course.assignmentsId})})
.then(res =>
{ {
// Get response body text // Check success
res.text().then(text => if (response.success)
{ {
// Parse response // Load assignments
let response = JSON.parse(text); // Parse json and filter it
course.assignments = JsonUtils.filterAssignments(response.data);
// Check success }
if (response.success) else
{ {
// Load assignments // Show error message TODO: Show it properly
// Parse json and filter it alert(response.data);
course.assignments = JsonUtils.filterAssignments(response.data); }
}
else
{
// Show error message TODO: Show it properly
alert(response.data);
}
})
}) })
.catch(err => .catch(alert);
{
alert(err);
});
}); });
// Wait for assignments to be ready. // Wait for assignments to be ready.