From 89b8dbe57f9f602588397244880fb07afc9b14d3 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 20 Oct 2020 23:08:30 +0200 Subject: [PATCH] added online check to prevent message spam --- cookbook/templates/shopping_list.html | 29 ++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html index c5817c6d4..5118bc1ab 100644 --- a/cookbook/templates/shopping_list.html +++ b/cookbook/templates/shopping_list.html @@ -225,6 +225,16 @@
+ {% if request.user.userpreference.shopping_auto_sync > 0 %} +
+
+ +
+
+ {% endif %} +
@@ -326,6 +336,7 @@ units_loading: false, users: [], users_loading: false, + onLine: navigator.onLine, }, directives: { tabindex: { @@ -365,7 +376,7 @@ text += `${this.export_text_prefix}${e.amount} ${e.unit.name} ${e.food.name} \n` } return text - }, + } }, /* watch: { @@ -399,15 +410,24 @@ {% if request.user.userpreference.shopping_auto_sync > 0 %} setInterval(() => { - if ((this.shopping_list_id !== null) && !this.edit_mode) { + if ((this.shopping_list_id !== null) && !this.edit_mode && window.navigator.onLine) { this.loadShoppingList(true) } }, {% widthratio request.user.userpreference.shopping_auto_sync 1 1000 %}) + + window.addEventListener('online', this.updateOnlineStatus); + window.addEventListener('offline', this.updateOnlineStatus); {% endif %} this.searchUsers('') }, methods: { + updateOnlineStatus(e) { + const { + type + } = e; + this.onLine = type === 'online'; + }, /* warnPageLeave: function (event) { if (this.recipe_changed) { @@ -672,7 +692,10 @@ this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') }) }, - + }, + beforeDestroy() { + window.removeEventListener('online', this.updateOnlineStatus); + window.removeEventListener('offline', this.updateOnlineStatus); } });