fix: mis-ordered shoppinglist after checking item (#1749)

This commit is contained in:
Hayden 2022-10-21 20:35:45 -08:00 committed by GitHub
parent 558789cd02
commit a56bedb022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@
<ShoppingListItem <ShoppingListItem
v-model="listItems.unchecked[index]" v-model="listItems.unchecked[index]"
class="my-2 my-sm-0" class="my-2 my-sm-0"
:labels="allLabels" :labels="allLabels || []"
:units="allUnits || []" :units="allUnits || []"
:foods="allFoods || []" :foods="allFoods || []"
@checked="saveListItem(item)" @checked="saveListItem(item)"
@ -40,7 +40,7 @@
<v-lazy v-for="(item, index) in value" :key="item.id"> <v-lazy v-for="(item, index) in value" :key="item.id">
<ShoppingListItem <ShoppingListItem
v-model="value[index]" v-model="value[index]"
:labels="allLabels" :labels="allLabels || []"
:units="allUnits || []" :units="allUnits || []"
:foods="allFoods || []" :foods="allFoods || []"
@checked="saveListItem(item)" @checked="saveListItem(item)"
@ -56,7 +56,7 @@
<ShoppingListItemEditor <ShoppingListItemEditor
v-model="createListItemData" v-model="createListItemData"
class="my-4" class="my-4"
:labels="allLabels" :labels="allLabels || []"
:units="allUnits || []" :units="allUnits || []"
:foods="allFoods || []" :foods="allFoods || []"
@delete="createEditorOpen = false" @delete="createEditorOpen = false"
@ -439,11 +439,22 @@ export default defineComponent({
// ===================================== // =====================================
// List Item CRUD // List Item CRUD
/*
* saveListItem updates and update on the backend server. Additionally, if the item is
* checked it will also append that item to the end of the list so that the unchecked items
* are at the top of the list.
*/
async function saveListItem(item: ShoppingListItemOut) { async function saveListItem(item: ShoppingListItemOut) {
if (!shoppingList.value) { if (!shoppingList.value) {
return; return;
} }
if (item.checked && shoppingList.value.listItems) {
const lst = shoppingList.value.listItems.filter((itm) => itm.id !== item.id);
lst.push(item);
updateIndex(lst);
}
const { data } = await userApi.shopping.items.updateOne(item.id, item); const { data } = await userApi.shopping.items.updateOne(item.id, item);
if (data) { if (data) {