diff --git a/frontend/pages/group/data/labels.vue b/frontend/pages/group/data/labels.vue index b22cca53752..ece501144fe 100644 --- a/frontend/pages/group/data/labels.vue +++ b/frontend/pages/group/data/labels.vue @@ -17,6 +17,7 @@ v-model="state.editDialog" :icon="$globals.icons.tags" :title="$t('data-pages.labels.edit-label')" + :submit-icon="$globals.icons.save" :submit-text="$tc('general.save')" @submit="editSaveLabel" > diff --git a/frontend/pages/shopping-lists/_id.vue b/frontend/pages/shopping-lists/_id.vue index 11d0342cef7..2f1f99385a7 100644 --- a/frontend/pages/shopping-lists/_id.vue +++ b/frontend/pages/shopping-lists/_id.vue @@ -58,11 +58,18 @@ - + - -
- + +
+
@@ -103,7 +110,9 @@ />
- + {{ $t('shopping-list.reorder-labels') }} @@ -492,6 +501,8 @@ export default defineComponent({ // Labels, Units, Foods // TODO: Extract to Composable + const localLabels = ref() + const { labels: allLabels } = useLabelStore(); const { units: allUnits } = useUnitStore(); const { foods: allFoods } = useFoodStore(); @@ -505,7 +516,10 @@ export default defineComponent({ } function toggleReorderLabelsDialog() { + // stop polling and populate localLabels + loadingCounter.value += 1 reorderLabelsDialog.value = !reorderLabelsDialog.value + localLabels.value = shoppingList.value?.labelSettings } async function toggleSettingsDialog() { @@ -515,7 +529,7 @@ export default defineComponent({ settingsDialog.value = !settingsDialog.value; } - async function updateLabelOrder(labelSettings: ShoppingListMultiPurposeLabelOut[]) { + function updateLabelOrder(labelSettings: ShoppingListMultiPurposeLabelOut[]) { if (!shoppingList.value) { return; } @@ -525,16 +539,31 @@ export default defineComponent({ return labelSetting; }); - // setting this doesn't have any effect on the data since it's refreshed automatically, but it makes the ux feel smoother - shoppingList.value.labelSettings = labelSettings; - updateListItemOrder(); + localLabels.value = labelSettings + } + + function cancelLabelOrder() { + loadingCounter.value -= 1 + if (!shoppingList.value) { + return; + } + // restore original state + localLabels.value = shoppingList.value.labelSettings + } + + async function saveLabelOrder() { + if (!shoppingList.value || !localLabels.value || (localLabels.value === shoppingList.value.labelSettings)) { + return; + } loadingCounter.value += 1; - const { data } = await userApi.shopping.lists.updateLabelSettings(shoppingList.value.id, labelSettings); + const { data } = await userApi.shopping.lists.updateLabelSettings(shoppingList.value.id, localLabels.value); loadingCounter.value -= 1; if (data) { - refresh(); + // update shoppingList labels using the API response + shoppingList.value.labelSettings = (data as ShoppingListOut).labelSettings; + updateItemsByLabel(); } } @@ -940,7 +969,10 @@ export default defineComponent({ toggleReorderLabelsDialog, settingsDialog, toggleSettingsDialog, + localLabels, updateLabelOrder, + cancelLabelOrder, + saveLabelOrder, saveListItem, shoppingList, showChecked,