mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-06 10:38:50 +01:00
🗨️ fix: Prompts Pagination (#9385)
* 🗨️ fix: Prompts Pagination
* ci: Simplify user middleware setup in prompt tests
This commit is contained in:
parent
3a47deac07
commit
460eac36f6
13 changed files with 536 additions and 237 deletions
|
|
@ -400,22 +400,27 @@ export const usePromptGroupsInfiniteQuery = (
|
|||
params?: t.TPromptGroupsWithFilterRequest,
|
||||
config?: UseInfiniteQueryOptions<t.PromptGroupListResponse, unknown>,
|
||||
) => {
|
||||
const { name, pageSize, category, ...rest } = params || {};
|
||||
const { name, pageSize, category } = params || {};
|
||||
return useInfiniteQuery<t.PromptGroupListResponse, unknown>(
|
||||
[QueryKeys.promptGroups, name, category, pageSize],
|
||||
({ pageParam = '1' }) =>
|
||||
dataService.getPromptGroups({
|
||||
...rest,
|
||||
({ pageParam }) => {
|
||||
const queryParams: t.TPromptGroupsWithFilterRequest = {
|
||||
name,
|
||||
category: category || '',
|
||||
pageNumber: pageParam?.toString(),
|
||||
pageSize: (pageSize || 10).toString(),
|
||||
}),
|
||||
limit: (pageSize || 10).toString(),
|
||||
};
|
||||
|
||||
// Only add cursor if it's a valid string
|
||||
if (pageParam && typeof pageParam === 'string') {
|
||||
queryParams.cursor = pageParam;
|
||||
}
|
||||
|
||||
return dataService.getPromptGroups(queryParams);
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => {
|
||||
const currentPageNumber = Number(lastPage.pageNumber);
|
||||
const totalPages = Number(lastPage.pages);
|
||||
return currentPageNumber < totalPages ? currentPageNumber + 1 : undefined;
|
||||
// Use cursor-based pagination - ensure we return a valid cursor or undefined
|
||||
return lastPage.has_more && lastPage.after ? lastPage.after : undefined;
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue