From 45a34ceb3550c124b0d504d681f40a211a5ca229 Mon Sep 17 00:00:00 2001 From: hay-kot Date: Sun, 30 May 2021 13:13:41 -0800 Subject: [PATCH] cleanup redundant code --- .../src/components/MealPlan/MealPlanNew.vue | 39 +++++++------------ .../src/components/UI/Buttons/TheButton.vue | 5 +++ frontend/src/utils/index.js | 4 +- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/MealPlan/MealPlanNew.vue b/frontend/src/components/MealPlan/MealPlanNew.vue index 26b0a0259..71c3ad6e3 100644 --- a/frontend/src/components/MealPlan/MealPlanNew.vue +++ b/frontend/src/components/MealPlan/MealPlanNew.vue @@ -67,12 +67,13 @@ - + + {{ $t("general.random") }} - - - {{ $t("general.save") }} - + + @@ -105,6 +106,9 @@ export default { }, watch: { + startDate(val) { + console.log(val); + }, dateDif() { this.planDays = []; for (let i = 0; i < this.dateDif; i++) { @@ -138,16 +142,10 @@ export default { return Date.parse(this.endDate); }, dateDif() { - let startDate = new Date(this.startDate); - let endDate = new Date(this.endDate); - console.log(startDate, endDate); - - let dateDif = (endDate - startDate) / (1000 * 3600 * 24) + 1; - + let dateDif = (this.actualEndDate - this.actualStartDate) / (1000 * 3600 * 24) + 1; if (dateDif < 1) { return null; } - return dateDif; }, startComputedDateFormatted() { @@ -179,22 +177,17 @@ export default { }, random() { this.usedRecipes = [1]; - this.planDays.forEach((element, index) => { + this.planDays.forEach((_, index) => { let recipe = this.getRandom(this.filteredRecipes); this.planDays[index]["meals"][0]["slug"] = recipe.slug; this.planDays[index]["meals"][0]["name"] = recipe.name; this.usedRecipes.push(recipe); }); }, - processTime(index) { - let dateText = new Date(this.actualStartDate.valueOf() + 1000 * 3600 * 24 * index); - return dateText; - }, getDate(index) { - const dateObj = this.processTime(index); + const dateObj = new Date(this.actualStartDate.valueOf() + 1000 * 3600 * 24 * index); return utils.getDateAsPythonDate(dateObj); }, - async save() { const mealBody = { group: this.groupSettings.name, @@ -209,7 +202,6 @@ export default { this.endDate = null; } }, - formatDate(date) { if (!date) return null; @@ -227,12 +219,9 @@ export default { const nextEndDate = new Date(nextMonday); nextEndDate.setDate(nextEndDate.getDate() + 4); - this.startDate = nextMonday.toISOString().substr(0, 10); - - this.endDate = nextEndDate.toISOString().substr(0, 10); + this.startDate = utils.getDateAsPythonDate(nextMonday); + this.endDate = utils.getDateAsPythonDate(nextEndDate); }, }, }; - - diff --git a/frontend/src/components/UI/Buttons/TheButton.vue b/frontend/src/components/UI/Buttons/TheButton.vue index cc9fce06b..1f51be9e4 100644 --- a/frontend/src/components/UI/Buttons/TheButton.vue +++ b/frontend/src/components/UI/Buttons/TheButton.vue @@ -4,6 +4,7 @@ :small="small" :x-small="xSmall" :loading="loading" + :disabled="disabled" @click="$emit('click')" :outlined="btnStyle.outlined" :text="btnStyle.text" @@ -49,6 +50,10 @@ export default { type: Boolean, default: false, }, + disabled: { + type: Boolean, + default: false, + }, // Styles small: { type: Boolean, diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index 8d8139366..18093474d 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -6,10 +6,10 @@ import { store } from "@/store"; export const utils = { recipe: recipe, generateUniqueKey(item, index) { - const uniqueKey = `${item}-${index}`; - return uniqueKey; + return `${item}-${index}`; }, getDateAsPythonDate(dateObject) { + if (!dateObject) return null; const month = dateObject.getMonth() + 1; const day = dateObject.getDate(); const year = dateObject.getFullYear();