From a12f43ca0577cda215ceef4dafb5ab506fda43d2 Mon Sep 17 00:00:00 2001 From: Karthik Vempati Date: Fri, 22 Jul 2022 20:44:29 +0200 Subject: [PATCH 1/5] Alignment issues and what not More commits incoming --- frontend/src/components/RecipeModel.vue | 167 +++++++++++------------- 1 file changed, 75 insertions(+), 92 deletions(-) diff --git a/frontend/src/components/RecipeModel.vue b/frontend/src/components/RecipeModel.vue index 7bfcc72..c6db830 100644 --- a/frontend/src/components/RecipeModel.vue +++ b/frontend/src/components/RecipeModel.vue @@ -30,67 +30,84 @@ - @@ -98,43 +115,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From de33798a715184e73afc497bb6330155b9036c51 Mon Sep 17 00:00:00 2001 From: Karthik Vempati Date: Fri, 22 Jul 2022 20:56:07 +0200 Subject: [PATCH 3/5] rework random generation --- frontend/src/Api.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/Api.js b/frontend/src/Api.js index 76ac30e..e9c31ac 100644 --- a/frontend/src/Api.js +++ b/frontend/src/Api.js @@ -22,5 +22,11 @@ export default { }] }), + getRandom: () => instance.get('/api/v1/recipe/random', { + transformResponse: [function (data) { + return data? JSON.parse(data) : data; + }] + }), + removeForId: (id) => instance.delete('/api/v1/items/'+ id) } \ No newline at end of file From 8259f3b15876e0e05c26779741e65c1bbdf852ce Mon Sep 17 00:00:00 2001 From: Karthik Vempati Date: Fri, 22 Jul 2022 21:21:01 +0200 Subject: [PATCH 4/5] rework recipes and random generation pt. 2 --- frontend/src/components/RecipeModel.vue | 64 ++++++++++++++++++------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/RecipeModel.vue b/frontend/src/components/RecipeModel.vue index c6db830..7374cbc 100644 --- a/frontend/src/components/RecipeModel.vue +++ b/frontend/src/components/RecipeModel.vue @@ -35,9 +35,7 @@
- - { - this.$log.debug("Data loaded: ", response.data) - this.recipes = response.data - }) - .catch(error => { - this.$log.debug(error) - this.error = "Failed to load recipes" - }) - .finally(() => this.loading = false) + this.populateRecipes() }, + methods: { + populateFromFridge() { + api.getRecipesForFridge() + .then(response => { + this.$log.debug("Data loaded: ", response.data) + this.recipes = response.data + }) + .catch(error => { + this.$log.debug(error) + this.error = "Failed to load recipes" + }) + .finally(() => this.loading = false) + }, + + populateRandom() { + api.getRandom() + .then(response => { + this.$log.debug("Data loaded: ", response.data) + this.recipes = response.data + }) + .catch(error => { + this.$log.debug(error) + this.error = "Failed to load recipes" + }) + .finally(() => this.loading = false) + }, + + populateRecipes() { + api.getAll() + .then(response => { + this.$log.debug("Data loaded: ", response.data) + this.items = response.data + }) + .catch(error => { + this.$log.debug(error) + this.error = "Failed to load items" + }) + .finally(() => { + if (this.items.length > 3) { + this.populateFromFridge() + } else { + this.populateRandom() + } + }) + } + } } export default Recipes - - - - -