Bluesky app fork with some witchin' additions 💫

Add more Live Event refreshing (#9745)

* Refresh on foreground

* Add back interval

authored by

Eric Bailey and committed by
GitHub
3b780696 49e7a96c

+15 -10
+1 -1
src/analytics/metrics/client.ts
··· 51 51 } 52 52 this.queue.push(e) 53 53 54 - logger.info(`event: ${e.event as string}`, e) 54 + logger.debug(`event: ${e.event as string}`, e) 55 55 56 56 if (this.queue.length > this.maxBatchSize) { 57 57 this.flush()
+7 -2
src/features/liveEvents/context.tsx
··· 1 1 import {createContext, useContext, useMemo} from 'react' 2 2 import {QueryClient, useQuery} from '@tanstack/react-query' 3 3 4 + import {useOnAppStateChange} from '#/lib/appState' 4 5 import {useIsBskyTeam} from '#/lib/hooks/useIsBskyTeam' 5 6 import { 6 7 convertBskyAppUrlIfNeeded, ··· 35 36 export function Provider({children}: React.PropsWithChildren<{}>) { 36 37 const [isDevMode] = useDevMode() 37 38 const isBskyTeam = useIsBskyTeam() 38 - const {data} = useQuery( 39 + const {data, refetch} = useQuery( 39 40 { 40 41 // keep this, prefectching handles initial load 41 42 staleTime: 1000 * 15, 42 43 queryKey: liveEventsQueryKey, 43 - refetchInterval: 1000 * 60 * 5, 44 + refetchInterval: 1000 * 60 * 5, // refetch every 5 minutes 44 45 async queryFn() { 45 46 return fetchLiveEvents() 46 47 }, 47 48 }, 48 49 qc, 49 50 ) 51 + 52 + useOnAppStateChange(state => { 53 + if (state === 'active') refetch() 54 + }) 50 55 51 56 const ctx = useMemo(() => { 52 57 if (!data) return DEFAULT_LIVE_EVENTS
+7 -7
src/lib/appState.ts
··· 12 12 }) 13 13 } 14 14 15 - export function useAppState() { 16 - const [state, setState] = useState(AppState.currentState) 17 - 15 + export function useOnAppStateChange(cb: (state: AppStateStatus) => void) { 18 16 useEffect(() => { 19 - const sub = onAppStateChange(next => { 20 - setState(next) 21 - }) 17 + const sub = onAppStateChange(next => cb(next)) 22 18 return () => sub.remove() 23 - }, []) 19 + }, [cb]) 20 + } 24 21 22 + export function useAppState() { 23 + const [state, setState] = useState(AppState.currentState) 24 + useOnAppStateChange(setState) 25 25 return state 26 26 }