[O] Optimize loadCourses request
This commit is contained in:
+14
-25
@@ -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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user