mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Simplify and improve pagination
This commit is contained in:
@ -11,14 +11,14 @@ import apiInstance from '@utils/api/instance'
|
||||
import { featureCheck } from '@utils/helpers/featureCheck'
|
||||
import { useNavState } from '@utils/navigation/navigators'
|
||||
import { queryClient } from '@utils/queryHooks'
|
||||
import { StorageAccount } from '@utils/storage/account'
|
||||
import { getAccountStorage, setAccountStorage } from '@utils/storage/actions'
|
||||
import { getAccountStorage } from '@utils/storage/actions'
|
||||
import { AxiosError } from 'axios'
|
||||
import { uniqBy } from 'lodash'
|
||||
import { searchLocalStatus } from './search'
|
||||
import deleteItem from './timeline/deleteItem'
|
||||
import editItem from './timeline/editItem'
|
||||
import updateStatusProperty from './timeline/updateStatusProperty'
|
||||
import { infinitePageParams } from './utils'
|
||||
|
||||
export type QueryKeyTimeline = [
|
||||
'Timeline',
|
||||
@ -156,7 +156,16 @@ export const queryFunctionTimeline = async ({
|
||||
case 'Account':
|
||||
if (!page.id) return Promise.reject('Timeline query account id not provided')
|
||||
|
||||
if (page.exclude_reblogs) {
|
||||
if (page.only_media) {
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: {
|
||||
only_media: 'true',
|
||||
...params
|
||||
}
|
||||
})
|
||||
} else if (page.exclude_reblogs) {
|
||||
if (pageParam && pageParam.hasOwnProperty('max_id')) {
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
@ -196,8 +205,8 @@ export const queryFunctionTimeline = async ({
|
||||
url: `accounts/${page.id}/statuses`,
|
||||
params: {
|
||||
...params,
|
||||
exclude_replies: page.exclude_reblogs.toString(),
|
||||
only_media: page.only_media.toString()
|
||||
exclude_replies: false,
|
||||
only_media: false
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -247,14 +256,18 @@ const useTimelineQuery = ({
|
||||
options,
|
||||
...queryKeyParams
|
||||
}: QueryKeyTimeline[1] & {
|
||||
options?: UseInfiniteQueryOptions<PagedResponse<Mastodon.Status[]>, AxiosError>
|
||||
options?: Omit<
|
||||
UseInfiniteQueryOptions<PagedResponse<Mastodon.Status[]>, AxiosError>,
|
||||
'getPreviousPageParam' | 'getNextPageParam'
|
||||
>
|
||||
}) => {
|
||||
const queryKey: QueryKeyTimeline = ['Timeline', { ...queryKeyParams }]
|
||||
return useInfiniteQuery(queryKey, queryFunctionTimeline, {
|
||||
refetchOnMount: false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnWindowFocus: false,
|
||||
...options
|
||||
...options,
|
||||
...infinitePageParams
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user