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

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