Bluesky app fork with some witchin' additions 💫

add focus refresh + polling (#3846)

authored by samuel.fm and committed by

GitHub ce02a411 4a2d4253

+23 -2
+17
src/components/hooks/useRefreshOnFocus.ts
··· 1 + import {useCallback, useRef} from 'react' 2 + import {useFocusEffect} from '@react-navigation/native' 3 + 4 + export function useRefreshOnFocus<T>(refetch: () => Promise<T>) { 5 + const firstTimeRef = useRef(true) 6 + 7 + useFocusEffect( 8 + useCallback(() => { 9 + if (firstTimeRef.current) { 10 + firstTimeRef.current = false 11 + return 12 + } 13 + 14 + refetch() 15 + }, [refetch]), 16 + ) 17 + }
+4 -1
src/screens/Messages/List/index.tsx
··· 27 27 import {ConvoMenu} from '#/components/dms/ConvoMenu' 28 28 import {NewChat} from '#/components/dms/NewChat' 29 29 import * as TextField from '#/components/forms/TextField' 30 + import {useRefreshOnFocus} from '#/components/hooks/useRefreshOnFocus' 30 31 import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' 31 32 import {SettingsSliderVertical_Stroke2_Corner0_Rounded as SettingsSlider} from '#/components/icons/SettingsSlider' 32 33 import {Link} from '#/components/Link' ··· 75 76 fetchNextPage, 76 77 error, 77 78 refetch, 78 - } = useListConvos() 79 + } = useListConvos({refetchInterval: 15_000}) 80 + 81 + useRefreshOnFocus(refetch) 79 82 80 83 const isError = !!error 81 84
+2 -1
src/state/queries/messages/list-converations.ts
··· 7 7 export const RQKEY = ['convo-list'] 8 8 type RQPageParam = string | undefined 9 9 10 - export function useListConvos() { 10 + export function useListConvos({refetchInterval}: {refetchInterval: number}) { 11 11 const headers = useHeaders() 12 12 const {serviceUrl} = useDmServiceUrlStorage() 13 13 ··· 24 24 }, 25 25 initialPageParam: undefined as RQPageParam, 26 26 getNextPageParam: lastPage => lastPage.cursor, 27 + refetchInterval, 27 28 }) 28 29 }