mirror of
https://github.com/tooot-app/app
synced 2025-02-06 05:13:35 +01:00
Now refreshing is more forgiving
This commit is contained in:
parent
b972cd6ca7
commit
25a80cc57e
@ -24,6 +24,15 @@ const client = async ({
|
||||
body?: FormData
|
||||
onUploadProgress?: (progressEvent: any) => void
|
||||
}): Promise<any> => {
|
||||
console.log(
|
||||
'API call:',
|
||||
'Method ->',
|
||||
method,
|
||||
'Endpoint ->',
|
||||
url,
|
||||
'Params ->',
|
||||
params
|
||||
)
|
||||
const state: RootState['instances'] = store.getState().instances
|
||||
const domain =
|
||||
instance === 'remote' ? instanceDomain || state.remote.url : state.local.url
|
||||
|
@ -57,20 +57,22 @@ const Timeline: React.FC<Props> = ({
|
||||
fetchNextPage,
|
||||
isFetchingNextPage
|
||||
} = useInfiniteQuery(queryKey, timelineFetch, {
|
||||
select: data => {
|
||||
return { ...data, pages: data.pages.filter(page => page.toots.length) }
|
||||
},
|
||||
getPreviousPageParam: firstPage => ({
|
||||
getPreviousPageParam: firstPage => {
|
||||
return firstPage.toots.length
|
||||
? {
|
||||
direction: 'prev',
|
||||
id: firstPage.toots[0].id
|
||||
}),
|
||||
getNextPageParam: lastPage =>
|
||||
lastPage.toots.length
|
||||
}
|
||||
: undefined
|
||||
},
|
||||
getNextPageParam: (lastPage, all) => {
|
||||
return lastPage.toots.length
|
||||
? {
|
||||
direction: 'next',
|
||||
id: lastPage.toots[lastPage.toots.length - 1].id
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
})
|
||||
const flattenData = data?.pages ? data.pages.flatMap(d => [...d?.toots]) : []
|
||||
const flattenPointer = data?.pages
|
||||
@ -131,10 +133,14 @@ const Timeline: React.FC<Props> = ({
|
||||
() => <TimelineEmpty status={status} refetch={refetch} />,
|
||||
[status]
|
||||
)
|
||||
const flOnRefresh = useCallback(
|
||||
() => !disableRefresh && fetchPreviousPage(),
|
||||
[]
|
||||
)
|
||||
const flOnRefresh = useCallback(() => {
|
||||
!disableRefresh &&
|
||||
(hasPreviousPage
|
||||
? fetchPreviousPage()
|
||||
: status !== 'loading'
|
||||
? refetch()
|
||||
: undefined)
|
||||
}, [hasPreviousPage, status])
|
||||
const flOnEndReach = useCallback(() => !disableRefresh && fetchNextPage(), [])
|
||||
const flFooter = useCallback(
|
||||
() => (!disableRefresh ? <TimelineEnd hasNextPage={hasNextPage} /> : null),
|
||||
@ -143,11 +149,14 @@ const Timeline: React.FC<Props> = ({
|
||||
const flRefreshControl = useMemo(
|
||||
() => (
|
||||
<RefreshControl
|
||||
refreshing={isFetchingPreviousPage}
|
||||
refreshing={
|
||||
isFetchingPreviousPage ||
|
||||
(!isFetchingNextPage && status === 'loading')
|
||||
}
|
||||
onRefresh={flOnRefresh}
|
||||
/>
|
||||
),
|
||||
[isFetchingPreviousPage]
|
||||
[isFetchingPreviousPage, isFetchingNextPage, status]
|
||||
)
|
||||
const onScrollToIndexFailed = useCallback(error => {
|
||||
const offset = error.averageItemLength * error.index
|
||||
|
Loading…
x
Reference in New Issue
Block a user