mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-30 17:53:31 -04:00 
			
		
		
		
	Feature/collapse recipe sections (#1021)
* toggle hide recipe sections * disable parser if food or units is defined * make inputs clearable * remove console.logs * fix linter error * fix linter errors
This commit is contained in:
		| @@ -44,6 +44,7 @@ | |||||||
|           item-text="name" |           item-text="name" | ||||||
|           class="mx-1" |           class="mx-1" | ||||||
|           placeholder="Choose Unit" |           placeholder="Choose Unit" | ||||||
|  |           clearable | ||||||
|           @keyup.enter="handleUnitEnter" |           @keyup.enter="handleUnitEnter" | ||||||
|         > |         > | ||||||
|           <template #no-data> |           <template #no-data> | ||||||
| @@ -70,6 +71,7 @@ | |||||||
|           item-text="name" |           item-text="name" | ||||||
|           class="mx-1 py-0" |           class="mx-1 py-0" | ||||||
|           placeholder="Choose Food" |           placeholder="Choose Food" | ||||||
|  |           clearable | ||||||
|           @keyup.enter="handleFoodEnter" |           @keyup.enter="handleFoodEnter" | ||||||
|         > |         > | ||||||
|           <template #no-data> |           <template #no-data> | ||||||
| @@ -165,15 +167,12 @@ export default defineComponent({ | |||||||
|  |  | ||||||
|     function handleUnitEnter() { |     function handleUnitEnter() { | ||||||
|       if (value.unit === undefined || value.unit === null || !value.unit.name.includes(unitSearch.value)) { |       if (value.unit === undefined || value.unit === null || !value.unit.name.includes(unitSearch.value)) { | ||||||
|         console.log("Creating"); |  | ||||||
|         createAssignUnit(); |         createAssignUnit(); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function handleFoodEnter() { |     function handleFoodEnter() { | ||||||
|       console.log(value.food); |  | ||||||
|       if (value.food === undefined || value.food === null || !value.food.name.includes(foodSearch.value)) { |       if (value.food === undefined || value.food === null || !value.food.name.includes(foodSearch.value)) { | ||||||
|         console.log("Creating"); |  | ||||||
|         createAssignFood(); |         createAssignFood(); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -76,7 +76,15 @@ | |||||||
|       @end="drag = false" |       @end="drag = false" | ||||||
|     > |     > | ||||||
|       <div v-for="(step, index) in value" :key="step.id"> |       <div v-for="(step, index) in value" :key="step.id"> | ||||||
|         <v-app-bar v-if="showTitleEditor[step.id]" class="primary mx-1 mt-6" dark dense rounded> |         <v-app-bar | ||||||
|  |           v-if="showTitleEditor[step.id]" | ||||||
|  |           class="primary mx-1 mt-6" | ||||||
|  |           style="cursor: pointer" | ||||||
|  |           dark | ||||||
|  |           dense | ||||||
|  |           rounded | ||||||
|  |           @click="toggleCollapseSection(index)" | ||||||
|  |         > | ||||||
|           <v-toolbar-title v-if="!edit" class="headline"> |           <v-toolbar-title v-if="!edit" class="headline"> | ||||||
|             <v-app-bar-title v-text="step.title"> </v-app-bar-title> |             <v-app-bar-title v-text="step.title"> </v-app-bar-title> | ||||||
|           </v-toolbar-title> |           </v-toolbar-title> | ||||||
| @@ -180,7 +188,7 @@ | |||||||
| import draggable from "vuedraggable"; | import draggable from "vuedraggable"; | ||||||
| // @ts-ignore vue-markdown has no types | // @ts-ignore vue-markdown has no types | ||||||
| import VueMarkdown from "@adapttive/vue-markdown"; | import VueMarkdown from "@adapttive/vue-markdown"; | ||||||
| import { ref, toRefs, reactive, defineComponent, watch, onMounted, watchEffect } from "@nuxtjs/composition-api"; | import { ref, toRefs, reactive, defineComponent, watch, onMounted } from "@nuxtjs/composition-api"; | ||||||
| import { RecipeStep, IngredientReferences, RecipeIngredient } from "~/types/api-types/recipe"; | import { RecipeStep, IngredientReferences, RecipeIngredient } from "~/types/api-types/recipe"; | ||||||
| import { parseIngredientText } from "~/composables/recipes"; | import { parseIngredientText } from "~/composables/recipes"; | ||||||
| import { uuid4 } from "~/composables/use-utils"; | import { uuid4 } from "~/composables/use-utils"; | ||||||
| @@ -452,8 +460,29 @@ export default defineComponent({ | |||||||
|       previewStates.value = temp; |       previewStates.value = temp; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     function toggleCollapseSection(index: number) { | ||||||
|  |       const sectionSteps: number[] = []; | ||||||
|  |  | ||||||
|  |       for (let i = index; i < props.value.length; i++) { | ||||||
|  |         if (!(i === index) && validateTitle(props.value[i].title)) { | ||||||
|  |           break; | ||||||
|  |         } else { | ||||||
|  |           sectionSteps.push(i); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       const allCollapsed = sectionSteps.every((idx) => state.disabledSteps.includes(idx)); | ||||||
|  |  | ||||||
|  |       if (allCollapsed) { | ||||||
|  |         state.disabledSteps = state.disabledSteps.filter((idx) => !sectionSteps.includes(idx)); | ||||||
|  |       } else { | ||||||
|  |         state.disabledSteps = [...state.disabledSteps, ...sectionSteps]; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|       togglePreviewState, |       togglePreviewState, | ||||||
|  |       toggleCollapseSection, | ||||||
|       previewStates, |       previewStates, | ||||||
|       ...toRefs(state), |       ...toRefs(state), | ||||||
|       actionEvents, |       actionEvents, | ||||||
|   | |||||||
| @@ -142,7 +142,7 @@ | |||||||
|                 <template #activator="{ on, attrs }"> |                 <template #activator="{ on, attrs }"> | ||||||
|                   <span v-on="on"> |                   <span v-on="on"> | ||||||
|                     <BaseButton |                     <BaseButton | ||||||
|                       :disabled="recipe.settings.disableAmount" |                       :disabled="recipe.settings.disableAmount || hasFoodOrUnit" | ||||||
|                       color="accent" |                       color="accent" | ||||||
|                       :to="`${recipe.slug}/ingredient-parser`" |                       :to="`${recipe.slug}/ingredient-parser`" | ||||||
|                       v-bind="attrs" |                       v-bind="attrs" | ||||||
| @@ -154,9 +154,7 @@ | |||||||
|                     </BaseButton> |                     </BaseButton> | ||||||
|                   </span> |                   </span> | ||||||
|                 </template> |                 </template> | ||||||
|                 <span>{{ |                 <span>{{ paserToolTip }}</span> | ||||||
|                   recipe.settings.disableAmount ? "Enable ingredient amounts to use this feature" : "Parse ingredients" |  | ||||||
|                 }}</span> |  | ||||||
|               </v-tooltip> |               </v-tooltip> | ||||||
|               <RecipeDialogBulkAdd class="ml-1 mr-1" @bulk-data="addIngredient" /> |               <RecipeDialogBulkAdd class="ml-1 mr-1" @bulk-data="addIngredient" /> | ||||||
|               <BaseButton @click="addIngredient"> {{ $t("general.new") }} </BaseButton> |               <BaseButton @click="addIngredient"> {{ $t("general.new") }} </BaseButton> | ||||||
| @@ -798,6 +796,30 @@ export default defineComponent({ | |||||||
|  |  | ||||||
|     useMeta(metaData); |     useMeta(metaData); | ||||||
|  |  | ||||||
|  |     const hasFoodOrUnit = computed(() => { | ||||||
|  |       if (!recipe.value) { | ||||||
|  |         return false; | ||||||
|  |       } | ||||||
|  |       if (recipe.value.recipeIngredient) { | ||||||
|  |         for (const ingredient of recipe.value.recipeIngredient) { | ||||||
|  |           if (ingredient.food || ingredient.unit) { | ||||||
|  |             return true; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       return false; | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     const paserToolTip = computed(() => { | ||||||
|  |       if (recipe.value?.settings?.disableAmount) { | ||||||
|  |         return "Enable ingredient amounts to use this feature"; | ||||||
|  |       } else if (hasFoodOrUnit.value) { | ||||||
|  |         return "Recipes with units or foods defined cannot be parsed."; | ||||||
|  |       } | ||||||
|  |       return "Parse ingredients"; | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     return { |     return { | ||||||
|       // Wake Lock |       // Wake Lock | ||||||
|       wakeIsSupported, |       wakeIsSupported, | ||||||
| @@ -806,6 +828,8 @@ export default defineComponent({ | |||||||
|       unlockScreen, |       unlockScreen, | ||||||
|       wakeLock, |       wakeLock, | ||||||
|       // |       // | ||||||
|  |       hasFoodOrUnit, | ||||||
|  |       paserToolTip, | ||||||
|       originalRecipe, |       originalRecipe, | ||||||
|       createApiExtra, |       createApiExtra, | ||||||
|       apiNewKey, |       apiNewKey, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user