bsky-app/src/state/events.ts
dan 57be2ea15b
Don't kick to login screen on network error (#4911)
* Don't kick the user on network errors

* Track online status for RQ

* Use health endpoint

* Update test with new behavior

* Only poll while offline

* Handle races between the check and network events

* Reduce the poll kickoff interval

* Don't cache partially fetched pinned feeds

This isn't a new issue but it's more prominent with the offline handling. We're currently silently caching pinned infos that failed to fetch. This avoids showing a big spinner on failure but it also kills all feeds which is very confusing. If the request to get feed gens fails, let's fail the whole query.

Then it can be retried.
2024-08-13 18:51:49 +01:00

47 lines
1.3 KiB
TypeScript

import EventEmitter from 'eventemitter3'
type UnlistenFn = () => void
const emitter = new EventEmitter()
// a "soft reset" typically means scrolling to top and loading latest
// but it can depend on the screen
export function emitSoftReset() {
emitter.emit('soft-reset')
}
export function listenSoftReset(fn: () => void): UnlistenFn {
emitter.on('soft-reset', fn)
return () => emitter.off('soft-reset', fn)
}
export function emitSessionDropped() {
emitter.emit('session-dropped')
}
export function listenSessionDropped(fn: () => void): UnlistenFn {
emitter.on('session-dropped', fn)
return () => emitter.off('session-dropped', fn)
}
export function emitNetworkConfirmed() {
emitter.emit('network-confirmed')
}
export function listenNetworkConfirmed(fn: () => void): UnlistenFn {
emitter.on('network-confirmed', fn)
return () => emitter.off('network-confirmed', fn)
}
export function emitNetworkLost() {
emitter.emit('network-lost')
}
export function listenNetworkLost(fn: () => void): UnlistenFn {
emitter.on('network-lost', fn)
return () => emitter.off('network-lost', fn)
}
export function emitPostCreated() {
emitter.emit('post-created')
}
export function listenPostCreated(fn: () => void): UnlistenFn {
emitter.on('post-created', fn)
return () => emitter.off('post-created', fn)
}