1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Added trending in the "public" tab
This commit is contained in:
xmflsct
2022-12-11 01:08:38 +01:00
parent 1ece7b3fe3
commit 44379504eb
23 changed files with 508 additions and 598 deletions

View File

@ -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 =

View File

@ -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 }

View File

@ -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 }
}