fixed v2 autosync flickering

This commit is contained in:
vabene1111
2022-01-21 16:44:03 +01:00
parent c5b70b94c7
commit 20adcc0e83

View File

@@ -715,7 +715,8 @@ export default {
new_supermarket: {entrymode: false, value: undefined, editmode: undefined}, new_supermarket: {entrymode: false, value: undefined, editmode: undefined},
new_category: {entrymode: false, value: undefined}, new_category: {entrymode: false, value: undefined},
autosync_id: undefined, autosync_id: undefined,
auto_sync_running: false, auto_sync_running: false, // track to not start a new sync before old one was finished
auto_sync_blocked: false, // blocking auto sync while request to check item is still running
show_delay: false, show_delay: false,
drag: false, drag: false,
show_modal: false, show_modal: false,
@@ -863,7 +864,7 @@ export default {
window.addEventListener("offline", this.updateOnlineStatus) window.addEventListener("offline", this.updateOnlineStatus)
} }
this.autosync_id = setInterval(() => { this.autosync_id = setInterval(() => {
if (this.online && !this.auto_sync_running) { if (this.online && !this.auto_sync_running && !this.auto_sync_blocked) {
this.auto_sync_running = true this.auto_sync_running = true
this.getShoppingList(true) this.getShoppingList(true)
} }
@@ -1071,8 +1072,10 @@ export default {
} }
this.loading = false this.loading = false
} else { } else {
if (!this.auto_sync_blocked) {
this.mergeShoppingList(results.data) this.mergeShoppingList(results.data)
} }
}
}) })
.catch((err) => { .catch((err) => {
console.log(err) console.log(err)
@@ -1195,6 +1198,7 @@ export default {
}, },
updateChecked: function (update) { updateChecked: function (update) {
// when checking a sub item don't refresh the screen until all entries complete but change class to cross out // when checking a sub item don't refresh the screen until all entries complete but change class to cross out
this.auto_sync_blocked = true
let promises = [] let promises = []
update.entries.forEach((x) => { update.entries.forEach((x) => {
const id = x?.id ?? x const id = x?.id ?? x
@@ -1209,7 +1213,10 @@ export default {
Vue.set(item, "completed_at", completed_at) Vue.set(item, "completed_at", completed_at)
}) })
Promise.all(promises).catch((err) => { Promise.all(promises).then(() => {
this.auto_sync_blocked = false
}).catch((err) => {
this.auto_sync_blocked = false
console.log(err, err.response) console.log(err, err.response)
StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE) StandardToasts.makeStandardToast(StandardToasts.FAIL_UPDATE)
}) })