brutalism design
This commit is contained in:
33
new-client/src/widgets/chat/api/qChatMessages.ts
Normal file
33
new-client/src/widgets/chat/api/qChatMessages.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { ChatMessage, ResponseError } from '@shared/api/generated-chad-api.ts'
|
||||
import type { InfiniteData, QueryKey } from '@tanstack/vue-query'
|
||||
import api from '@shared/api/client.ts'
|
||||
import { useInfiniteQuery } from '@tanstack/vue-query'
|
||||
|
||||
interface Response {
|
||||
messages: ChatMessage[]
|
||||
nextCursor?: string
|
||||
}
|
||||
type PageParam = string | undefined
|
||||
|
||||
export function qChatMessages() {
|
||||
return useInfiniteQuery<Response, ResponseError, InfiniteData<Response, PageParam>, QueryKey, PageParam>({
|
||||
queryKey: ['chat-messages'],
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const response = await api.chad.chatMessages({ cursor: pageParam, limit: 30 })
|
||||
|
||||
return {
|
||||
messages: response.data.messages.reverse(),
|
||||
nextCursor: response.data.nextCursor,
|
||||
}
|
||||
},
|
||||
select: data => ({
|
||||
pages: [...data.pages].reverse(),
|
||||
pageParams: [...data.pageParams].reverse(),
|
||||
}),
|
||||
initialPageParam: undefined,
|
||||
getNextPageParam: (lastPage) => {
|
||||
return lastPage.nextCursor
|
||||
},
|
||||
shallow: true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user