1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-23 07:09:41 +02:00

fix: #5511, list item state doesn't change when offline (#5512)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
Craig Matear 2025-06-17 19:41:35 +01:00 committed by GitHub
parent 079cfe7fe0
commit ac984a2d04
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 6 deletions

View file

@ -89,9 +89,31 @@ export function useShoppingListItemActions(shoppingListId: string) {
return true;
}
function mergeListItemsByLatest(
list1: ShoppingListItemOut[],
list2: ShoppingListItemOut[]
) {
const mergedList = [...list1];
list2.forEach((list2Item) => {
const conflictingItem = mergedList.find((item) => item.id === list2Item.id)
if (conflictingItem &&
list2Item.updatedAt && conflictingItem.updatedAt &&
list2Item.updatedAt > conflictingItem.updatedAt) {
mergedList.splice(mergedList.indexOf(conflictingItem), 1, list2Item)
} else if (!conflictingItem) {
mergedList.push(list2Item)
}
})
return mergedList
}
async function getList() {
const response = await api.shopping.lists.getOne(shoppingListId);
return response.data;
if (window.$nuxt.isOffline && response.data) {
const createAndUpdateQueues = mergeListItemsByLatest(queue.update, queue.create);
response.data.listItems = mergeListItemsByLatest(response.data.listItems ?? [], createAndUpdateQueues);
}
return response.data
}
function createItem(item: ShoppingListItemOut) {
@ -188,7 +210,7 @@ export function useShoppingListItemActions(shoppingListId: string) {
}
async function process() {
if(queueEmpty.value) {
if (queueEmpty.value) {
queue.lastUpdate = Date.now();
return;
}