autosync WIP

This commit is contained in:
vabene1111
2024-11-25 18:36:11 +01:00
parent 0485e5192b
commit d91a3080d5
41 changed files with 413 additions and 1876 deletions

View File

@@ -1,6 +1,8 @@
<template>
<v-tabs v-model="currentTab">
<v-tab value="shopping"><i class="fas fa-shopping-cart fa-fw"></i> <span class="d-none d-md-block ms-1">{{ $t('Shopping_list') }}</span></v-tab>
<v-tab value="shopping"><i class="fas fa-fw"
:class="{'fa-circle-notch fa-spin':useShoppingStore().currentlyUpdating, 'fa-shopping-cart ': !useShoppingStore().currentlyUpdating}"></i> <span
class="d-none d-md-block ms-1">{{ $t('Shopping_list') }}</span></v-tab>
<v-tab value="recipes"><i class="fas fa-book fa-fw"></i> <span class="d-none d-md-block ms-1">{{ $t('Recipes') }}</span></v-tab>
<v-menu :close-on-content-click="false">
@@ -32,7 +34,8 @@
<v-switch color="primary" hide-details :label="$t('ShowDelayed')" v-model="useUserPreferenceStore().deviceSettings.shopping_show_delayed_entries"></v-switch>
</v-list-item>
<v-list-item>
<v-switch color="primary" hide-details :label="$t('ShowRecentlyCompleted')" v-model="useUserPreferenceStore().deviceSettings.shopping_show_checked_entries"></v-switch>
<v-switch color="primary" hide-details :label="$t('ShowRecentlyCompleted')"
v-model="useUserPreferenceStore().deviceSettings.shopping_show_checked_entries"></v-switch>
</v-list-item>
</v-list>
</v-menu>
@@ -66,7 +69,7 @@
<template v-for="[i, value] in category.foods" :key="value.food.id">
<shopping-line-item :shopping-list-food="value" :entries="Array.from(value.entries.values())"
@clicked="args => {shoppingLineItemDialog = true; shoppingLineItemDialogFood = value; console.log('SETTING ITEMS')}"></shopping-line-item>
@clicked="args => {shoppingLineItemDialog = true; shoppingLineItemDialogFood = value;}"></shopping-line-item>
</template>
</template>
@@ -74,6 +77,22 @@
</v-list>
</v-col>
</v-row>
<v-row>
<v-col cols="4">
<v-card>
<v-card-title>Auto Sync Debug</v-card-title>
<v-card-text>
<v-list>
<v-list-item>currentlyUpdating: {{ useShoppingStore().currentlyUpdating }}</v-list-item>
<v-list-item>hasFocus: {{ useShoppingStore().autoSyncHasFocus }}</v-list-item>
<v-list-item>autoSyncTimeoutId: {{ useShoppingStore().autoSyncTimeoutId }}</v-list-item>
<v-list-item>autoSyncLastTimestamp: {{ useShoppingStore().autoSyncLastTimestamp }}</v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</v-window-item>
<v-window-item value="recipes">
@@ -134,7 +153,13 @@ const groupingOptionsItems = computed(() => {
})
onMounted(() => {
addEventListener("visibilitychange", (event) => {
useShoppingStore().autoSyncHasFocus = (document.visibilityState === 'visible')
});
useShoppingStore().refreshFromAPI()
autoSyncLoop()
})
/**
@@ -160,6 +185,23 @@ function addIngredient() {
})
}
/**
* run the autosync function in a loop
*/
function autoSyncLoop() {
// this should not happen in production but sometimes in development with HMR
clearTimeout(useShoppingStore().autoSyncTimeoutId)
let timeout = Math.max(useUserPreferenceStore().userSettings.shoppingAutoSync!, 1) * 1000 // if disabled (shopping_auto_sync=0) check again after 1 second if enabled
useShoppingStore().autoSyncTimeoutId = setTimeout(() => {
if (useUserPreferenceStore().userSettings.shoppingAutoSync! > 0) {
useShoppingStore().autoSync()
}
autoSyncLoop()
}, timeout)
}
</script>
<style scoped>