pinafore/src/routes/_store/observers/onlineObservers.js
Nolan Lawson a35f5ee2d9
feat: implement wellness settings (#1256)
* implement wellness settings

fixes #1192

Adds
- grayscale mode (as well as separate grayscale/dark grayscale
themes)
- disable follower/boost/fav counts (follower counts capped at 10)
- disable unread notification count (red dot)

* fix lint

* fix crawler
2019-06-01 13:07:31 -07:00

29 lines
788 B
JavaScript

import debounce from 'lodash-es/debounce'
import { toast } from '../../_components/toast/toast'
const OFFLINE_DELAY = 5000
const NOTIFY_OFFLINE_LIMIT = 1
let notifyCount = 0
// debounce to avoid notifying for a short connection issue
const notifyOffline = debounce(() => {
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) {
if (!process.browser) {
return
}
store.observe('online', online => {
if (!online) {
notifyOffline()
}
})
window.addEventListener('offline', () => store.set({ online: false }))
window.addEventListener('online', () => store.set({ online: true }))
}