[O] Optimize loadCourses request

This commit is contained in:
Hykilpikonna
2019-09-07 14:04:38 -04:00
parent 393fc1cc71
commit a7384753c8
+14 -25
View File
@@ -93,34 +93,23 @@ export default class App extends Vue
*/ */
public loadCoursesAfterLogin() public loadCoursesAfterLogin()
{ {
// Fetch request this.http.post('/courses', {}).then(response =>
fetch(`${Constants.API_URL}/courses`,
{method: 'POST', body: JSON.stringify({token: this.token})})
.then(res =>
{ {
// Get response body text // Check success
res.text().then(text => if (response.success)
{ {
// Parse response // Save courses
let response = JSON.parse(text); this.courses = response.data;
// Check success // Load assignments
if (response.success) this.loadAssignments();
{ }
// Save courses else
this.courses = response.data; {
// Show error message TODO: Show it properly
// Load assignments alert(response.data);
this.loadAssignments(); }
} });
else
{
// Show error message TODO: Show it properly
alert(response.data);
}
})
})
.catch(alert)
} }
/** /**