mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-04 06:04:53 -04:00
feat: Shopping List Editor Improvements (#3178)
* modify new item factory to default to zero qty and use last isFood value * automatically set the label of an item when choosing a food * fix when switching to a food with no label * removed trivial type annotation * more lint * removed debug log
This commit is contained in:
parent
a7775ea7ef
commit
ea7005e822
@ -95,7 +95,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, computed } from "@nuxtjs/composition-api";
|
import { defineComponent, computed, watch } from "@nuxtjs/composition-api";
|
||||||
import { ShoppingListItemCreate, ShoppingListItemOut } from "~/lib/api/types/group";
|
import { ShoppingListItemCreate, ShoppingListItemOut } from "~/lib/api/types/group";
|
||||||
import { MultiPurposeLabelOut } from "~/lib/api/types/labels";
|
import { MultiPurposeLabelOut } from "~/lib/api/types/labels";
|
||||||
import { IngredientFood, IngredientUnit } from "~/lib/api/types/recipe";
|
import { IngredientFood, IngredientUnit } from "~/lib/api/types/recipe";
|
||||||
@ -128,6 +128,16 @@ export default defineComponent({
|
|||||||
context.emit("input", val);
|
context.emit("input", val);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.value.food,
|
||||||
|
(newFood) => {
|
||||||
|
// @ts-ignore our logic already assumes there's a label attribute, even if TS doesn't think there is
|
||||||
|
listItem.value.label = newFood?.label || null;
|
||||||
|
listItem.value.labelId = listItem.value.label?.id || null;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
listItem,
|
listItem,
|
||||||
};
|
};
|
||||||
|
@ -644,15 +644,15 @@ export default defineComponent({
|
|||||||
// Create New Item
|
// Create New Item
|
||||||
|
|
||||||
const createEditorOpen = ref(false);
|
const createEditorOpen = ref(false);
|
||||||
const createListItemData = ref<ShoppingListItemCreate>(ingredientResetFactory());
|
const createListItemData = ref<ShoppingListItemCreate>(listItemFactory());
|
||||||
|
|
||||||
function ingredientResetFactory(): ShoppingListItemCreate {
|
function listItemFactory(isFood = false): ShoppingListItemCreate {
|
||||||
return {
|
return {
|
||||||
shoppingListId: id,
|
shoppingListId: id,
|
||||||
checked: false,
|
checked: false,
|
||||||
position: shoppingList.value?.listItems?.length || 1,
|
position: shoppingList.value?.listItems?.length || 1,
|
||||||
isFood: false,
|
isFood,
|
||||||
quantity: 1,
|
quantity: 0,
|
||||||
note: "",
|
note: "",
|
||||||
labelId: undefined,
|
labelId: undefined,
|
||||||
unitId: undefined,
|
unitId: undefined,
|
||||||
@ -675,7 +675,7 @@ export default defineComponent({
|
|||||||
loadingCounter.value -= 1;
|
loadingCounter.value -= 1;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
createListItemData.value = ingredientResetFactory();
|
createListItemData.value = listItemFactory(createListItemData.value.isFood || false);
|
||||||
createEditorOpen.value = false;
|
createEditorOpen.value = false;
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user