From 0efafdec90db8033e977e94f43c0c29b92454bfb Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 15 Apr 2018 16:00:16 -0700 Subject: [PATCH] only show "you are offline" notification once (#137) Fixes #34 --- routes/_store/observers/onlineObservers.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/routes/_store/observers/onlineObservers.js b/routes/_store/observers/onlineObservers.js index 2d6c8086..a1027825 100644 --- a/routes/_store/observers/onlineObservers.js +++ b/routes/_store/observers/onlineObservers.js @@ -1,10 +1,16 @@ import debounce from 'lodash-es/debounce' import { toast } from '../../_utils/toast' -const OFFLINE_DELAY = 1000 +const OFFLINE_DELAY = 5000 +const NOTIFY_OFFLINE_LIMIT = 1 +let notifyCount = 0 + +// debounce to avoid notifying for a short connection issue const notifyOffline = debounce(() => { - toast.say('You seem to be offline. You can still read toots while offline.') + if (process.browser && !navigator.onLine && ++notifyCount <= NOTIFY_OFFLINE_LIMIT) { + toast.say('You seem to be offline. You can still read toots while offline.') + } }, OFFLINE_DELAY) export function onlineObservers (store) {