mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-07 23:28:16 -05:00
proper async loading
This commit is contained in:
@@ -210,28 +210,37 @@
|
|||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
console.log("MOUNTED")
|
console.log("MOUNTED")
|
||||||
this.getPlanEntries();
|
this.updatePlan();
|
||||||
|
this.getRecipes();
|
||||||
},
|
},
|
||||||
methods: { // TODO stop chain loading and do async
|
methods: { // TODO stop chain loading and do async
|
||||||
|
updatePlan: function () {
|
||||||
|
let planEntryPromise = this.getPlanEntries();
|
||||||
|
let planTypePromise = this.getPlanTypes();
|
||||||
|
|
||||||
|
Promise.allSettled([planEntryPromise, planTypePromise]).then(() => {
|
||||||
|
this.buildGrid()
|
||||||
|
})
|
||||||
|
},
|
||||||
getPlanEntries: function () {
|
getPlanEntries: function () {
|
||||||
this.$http.get("{% url 'api:mealplan-list' %}?html_week=" + this.week).then((response) => {
|
console.log("GET PLAN EXECUTED")
|
||||||
|
return this.$http.get("{% url 'api:mealplan-list' %}?html_week=" + this.week).then((response) => {
|
||||||
this.plan_entries = response.data;
|
this.plan_entries = response.data;
|
||||||
this.getPlanTypes();
|
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
console.log(err);
|
console.log(err);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getPlanTypes: function () {
|
getPlanTypes: function () {
|
||||||
this.$http.get("{% url 'api:mealtype-list' %}").then((response) => {
|
console.log("GET TYPE EXECUTED")
|
||||||
|
return this.$http.get("{% url 'api:mealtype-list' %}").then((response) => {
|
||||||
this.meal_types = response.data;
|
this.meal_types = response.data;
|
||||||
this.buildGrid();
|
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
buildGrid: function () {
|
buildGrid: function () {
|
||||||
console.log("BUILD GRID EXECUTED")
|
console.log("BUILD GRID EXECUTED", this.plan_entries)
|
||||||
this.meal_plan = {}
|
this.meal_plan = {}
|
||||||
|
|
||||||
for (let t of this.meal_types) {
|
for (let t of this.meal_types) {
|
||||||
@@ -250,10 +259,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let e of this.plan_entries) {
|
for (let e of this.plan_entries) {
|
||||||
console.log(e.date)
|
|
||||||
this.meal_plan[e.meal_type].days[e.date].items.push(e)
|
this.meal_plan[e.meal_type].days[e.date].items.push(e)
|
||||||
}
|
}
|
||||||
this.getRecipes();
|
|
||||||
},
|
},
|
||||||
getRecipes: function () {
|
getRecipes: function () {
|
||||||
let url = "{% url 'api:recipe-list' %}?limit=5"
|
let url = "{% url 'api:recipe-list' %}?limit=5"
|
||||||
@@ -348,7 +355,7 @@
|
|||||||
},
|
},
|
||||||
changeWeek: function (change) {
|
changeWeek: function (change) {
|
||||||
this.week = moment(this.week).add(change, 'w').format('YYYY-[W]WW')
|
this.week = moment(this.week).add(change, 'w').format('YYYY-[W]WW')
|
||||||
this.getPlanEntries()
|
this.updatePlan();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user