only show "you are offline" notification once (#137)

Fixes #34
This commit is contained in:
Nolan Lawson 2018-04-15 16:00:16 -07:00 committed by GitHub
parent 300a399655
commit 0efafdec90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -1,10 +1,16 @@
import debounce from 'lodash-es/debounce' import debounce from 'lodash-es/debounce'
import { toast } from '../../_utils/toast' 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(() => { 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) }, OFFLINE_DELAY)
export function onlineObservers (store) { export function onlineObservers (store) {