Add more Live Event refreshing (#9745)
* Refresh on foreground * Add back interval
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {createContext, useContext, useMemo} from 'react'
|
||||
import {QueryClient, useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {useOnAppStateChange} from '#/lib/appState'
|
||||
import {useIsBskyTeam} from '#/lib/hooks/useIsBskyTeam'
|
||||
import {
|
||||
convertBskyAppUrlIfNeeded,
|
||||
@@ -35,12 +36,12 @@ const Context = createContext<LiveEventsWorkerResponse>(DEFAULT_LIVE_EVENTS)
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [isDevMode] = useDevMode()
|
||||
const isBskyTeam = useIsBskyTeam()
|
||||
const {data} = useQuery(
|
||||
const {data, refetch} = useQuery(
|
||||
{
|
||||
// keep this, prefectching handles initial load
|
||||
staleTime: 1000 * 15,
|
||||
queryKey: liveEventsQueryKey,
|
||||
refetchInterval: 1000 * 60 * 5,
|
||||
refetchInterval: 1000 * 60 * 5, // refetch every 5 minutes
|
||||
async queryFn() {
|
||||
return fetchLiveEvents()
|
||||
},
|
||||
@@ -48,6 +49,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
qc,
|
||||
)
|
||||
|
||||
useOnAppStateChange(state => {
|
||||
if (state === 'active') refetch()
|
||||
})
|
||||
|
||||
const ctx = useMemo(() => {
|
||||
if (!data) return DEFAULT_LIVE_EVENTS
|
||||
const feeds = data.feeds.filter(f => {
|
||||
|
||||
Reference in New Issue
Block a user