added online check to prevent message spam

This commit is contained in:
vabene1111
2020-10-20 23:08:30 +02:00
parent f2a17fe3bb
commit 89b8dbe57f

View File

@@ -225,6 +225,16 @@
</div> </div>
<div v-else> <div v-else>
{% if request.user.userpreference.shopping_auto_sync > 0 %}
<div class="row" v-if="!onLine">
<div class="col col-md-12">
<div class="alert alert-warning" role="alert">
{% trans 'You are offline, shopping list might not sync.' %}
</div>
</div>
</div>
{% endif %}
<div class="row" style="margin-top: 8px"> <div class="row" style="margin-top: 8px">
<div class="col col-md-12"> <div class="col col-md-12">
<table class="table"> <table class="table">
@@ -326,6 +336,7 @@
units_loading: false, units_loading: false,
users: [], users: [],
users_loading: false, users_loading: false,
onLine: navigator.onLine,
}, },
directives: { directives: {
tabindex: { tabindex: {
@@ -365,7 +376,7 @@
text += `${this.export_text_prefix}${e.amount} ${e.unit.name} ${e.food.name} \n` text += `${this.export_text_prefix}${e.amount} ${e.unit.name} ${e.food.name} \n`
} }
return text return text
}, }
}, },
/* /*
watch: { watch: {
@@ -399,15 +410,24 @@
{% if request.user.userpreference.shopping_auto_sync > 0 %} {% if request.user.userpreference.shopping_auto_sync > 0 %}
setInterval(() => { 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) this.loadShoppingList(true)
} }
}, {% widthratio request.user.userpreference.shopping_auto_sync 1 1000 %}) }, {% widthratio request.user.userpreference.shopping_auto_sync 1 1000 %})
window.addEventListener('online', this.updateOnlineStatus);
window.addEventListener('offline', this.updateOnlineStatus);
{% endif %} {% endif %}
this.searchUsers('') this.searchUsers('')
}, },
methods: { methods: {
updateOnlineStatus(e) {
const {
type
} = e;
this.onLine = type === 'online';
},
/* /*
warnPageLeave: function (event) { warnPageLeave: function (event) {
if (this.recipe_changed) { if (this.recipe_changed) {
@@ -672,7 +692,10 @@
this.makeToast('{% trans 'Error' %}', '{% trans 'There was an error loading a resource!' %}' + err.bodyText, 'danger') 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);
} }
}); });
</script> </script>