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