From 4d2363ea2217ff97a4793da34f74ed88173c8c09 Mon Sep 17 00:00:00 2001 From: Jurriaan Den Toonder <1493561+Fastjur@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:29:45 +0100 Subject: [PATCH] Add shopping list items using the enter key (#3118) * Enables shopping list items being saved upon enter key press in notes field Related to: https://github.com/mealie-recipes/mealie/discussions/3114 * Enter key press is caught in note field in ShoppingListItemEditor * The create editor now stays open after saving a food item to a shopping list, to allow keyboard-only interaction with the shopping list * Prevent empty shopping list items from being added Related to: https://github.com/mealie-recipes/mealie/discussions/3114 An item is considered empty when the foodId is not set, and no note is set. This is only handled frontend, the backend still accepts empty items. --------- Signed-off-by: Jurriaan Den Toonder <1493561+Fastjur@users.noreply.github.com> Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> --- .../Domain/ShoppingList/ShoppingListItemEditor.vue | 10 ++++++++++ frontend/pages/shopping-lists/_id.vue | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/components/Domain/ShoppingList/ShoppingListItemEditor.vue b/frontend/components/Domain/ShoppingList/ShoppingListItemEditor.vue index 249e3f121b0e..5b0f12611f45 100644 --- a/frontend/components/Domain/ShoppingList/ShoppingListItemEditor.vue +++ b/frontend/components/Domain/ShoppingList/ShoppingListItemEditor.vue @@ -25,6 +25,7 @@ :label="$t('shopping-list.note')" rows="1" auto-grow + @keypress="handleNoteKeyPress" >
@@ -142,5 +143,14 @@ export default defineComponent({ listItem, }; }, + methods: { + handleNoteKeyPress(event) { + // Save on Enter + if (!event.shiftKey && event.key === "Enter") { + event.preventDefault(); + this.$emit("save"); + } + }, + } }); diff --git a/frontend/pages/shopping-lists/_id.vue b/frontend/pages/shopping-lists/_id.vue index 9dabc3ae1e42..c5bdd2cc8249 100644 --- a/frontend/pages/shopping-lists/_id.vue +++ b/frontend/pages/shopping-lists/_id.vue @@ -665,6 +665,11 @@ export default defineComponent({ return; } + if (!createListItemData.value.foodId && !createListItemData.value.note) { + // don't create an empty item + return; + } + loadingCounter.value += 1; // make sure it's inserted into the end of the list, which may have been updated @@ -676,7 +681,6 @@ export default defineComponent({ if (data) { createListItemData.value = listItemFactory(createListItemData.value.isFood || false); - createEditorOpen.value = false; refresh(); } }