diff --git a/src/state/events.ts b/src/state/events.ts index 1384abdeda..928dff8788 100644 --- a/src/state/events.ts +++ b/src/state/events.ts @@ -29,3 +29,11 @@ export function listenPostCreated(fn: () => void): UnlistenFn { emitter.on('post-created', fn) return () => emitter.off('post-created', fn) } + +export function emitSessionResolved() { + emitter.emit('session-resolved') +} +export function listenOnSessionResolved(fn: () => void): UnlistenFn { + emitter.on('session-resolved', fn) + return () => emitter.off('session-resolved', fn) +} diff --git a/src/state/queries/preferences/moderation.ts b/src/state/queries/preferences/moderation.ts index 9cd183e8b1..1d983dd2ad 100644 --- a/src/state/queries/preferences/moderation.ts +++ b/src/state/queries/preferences/moderation.ts @@ -7,6 +7,7 @@ import { import {usePreferencesQuery} from './index' import {useLabelersDetailedInfoQuery} from '../labeler' +import {listenOnSessionResolved} from '#/state/events' /** * More strict than our default settings for logged in users. @@ -28,6 +29,13 @@ export function useMyLabelersQuery() { const labelers = useLabelersDetailedInfoQuery({dids}) const isLoading = prefs.isLoading || labelers.isLoading const error = prefs.error || labelers.error + + React.useEffect(() => { + return listenOnSessionResolved(() => { + labelers.refetch() + }) + }, [labelers]) + return React.useMemo(() => { return { isLoading, diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 6b14748393..158d151fd6 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -14,7 +14,7 @@ import {networkRetry} from '#/lib/async/retry' import {logger} from '#/logger' import * as persisted from '#/state/persisted' import {PUBLIC_BSKY_AGENT} from '#/state/queries' -import {emitSessionDropped} from '../events' +import {emitSessionDropped, emitSessionResolved} from '../events' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {useCloseAllActiveElements} from '#/state/util' import {track} from '#/lib/analytics/analytics' @@ -413,6 +413,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { `session: reuse of previous session returned a fresh account, upserting`, ) upsertAccount(freshAccount) + emitSessionResolved() } }) .catch(e => {