mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
@ -20,9 +20,11 @@ const queryFunction = async () => {
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useListsQuery = ({ options }: { options?: UseQueryOptions<Mastodon.List[], AxiosError> }) => {
|
||||
const useListsQuery = (
|
||||
params: { options?: UseQueryOptions<Mastodon.List[], AxiosError> } | void
|
||||
) => {
|
||||
const queryKey: QueryKeyLists = ['Lists']
|
||||
return useQuery(queryKey, queryFunction, options)
|
||||
return useQuery(queryKey, queryFunction, params?.options)
|
||||
}
|
||||
|
||||
type MutationVarsLists =
|
||||
|
@ -40,6 +40,7 @@ const queryFunction = async ({ queryKey, pageParam }: QueryFunctionContext<Query
|
||||
})
|
||||
|
||||
case 'Local':
|
||||
console.log('local', params)
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: 'timelines/public',
|
||||
@ -56,6 +57,14 @@ const queryFunction = async ({ queryKey, pageParam }: QueryFunctionContext<Query
|
||||
params
|
||||
})
|
||||
|
||||
case 'Trending':
|
||||
console.log('trending', params)
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: 'trends/statuses',
|
||||
params
|
||||
})
|
||||
|
||||
case 'Notifications':
|
||||
const rootStore = store.getState()
|
||||
const notificationsFilter = getInstanceNotificationsFilter(rootStore)
|
||||
@ -206,53 +215,6 @@ const useTimelineQuery = ({
|
||||
})
|
||||
}
|
||||
|
||||
const prefetchTimelineQuery = async ({
|
||||
ids,
|
||||
queryKey
|
||||
}: {
|
||||
ids: Mastodon.Status['id'][]
|
||||
queryKey: QueryKeyTimeline
|
||||
}): Promise<Mastodon.Status['id'] | undefined> => {
|
||||
let page: string = ''
|
||||
let local: boolean = false
|
||||
switch (queryKey[1].page) {
|
||||
case 'Following':
|
||||
page = 'home'
|
||||
break
|
||||
case 'Local':
|
||||
page = 'public'
|
||||
local = true
|
||||
break
|
||||
case 'LocalPublic':
|
||||
page = 'public'
|
||||
break
|
||||
}
|
||||
|
||||
for (const id of ids) {
|
||||
const statuses = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
url: `timelines/${page}`,
|
||||
params: {
|
||||
min_id: id,
|
||||
limit: 1,
|
||||
...(local && { local: 'true' })
|
||||
}
|
||||
})
|
||||
if (statuses.body.length) {
|
||||
await queryClient.prefetchInfiniteQuery(queryKey, props =>
|
||||
queryFunction({
|
||||
...props,
|
||||
queryKey,
|
||||
pageParam: {
|
||||
max_id: statuses.body[0].id
|
||||
}
|
||||
})
|
||||
)
|
||||
return id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Separator ---
|
||||
|
||||
enum MapPropertyToUrl {
|
||||
@ -460,4 +422,4 @@ const useTimelineMutation = ({
|
||||
})
|
||||
}
|
||||
|
||||
export { prefetchTimelineQuery, useTimelineQuery, useTimelineMutation }
|
||||
export { useTimelineQuery, useTimelineMutation }
|
||||
|
@ -2,7 +2,7 @@ import { InstanceResponse } from '@api/instance'
|
||||
|
||||
export const infinitePageParams = {
|
||||
getPreviousPageParam: (firstPage: InstanceResponse<any>) =>
|
||||
firstPage.links?.prev && { since_id: firstPage.links.next },
|
||||
firstPage.links?.prev && { min_id: firstPage.links.next },
|
||||
getNextPageParam: (lastPage: InstanceResponse<any>) =>
|
||||
lastPage.links?.next && { max_id: lastPage.links.next }
|
||||
}
|
||||
|
Reference in New Issue
Block a user