Add pagination support to project search

This commit adds support for pagination within the project search feature. The changes include adding a limit of 50 results per page and an offset to handle page offsets in the search. Additionally, the search results are now updated to include a 'haveMore' flag to indicate if there are more results to display.

Changes in detail:
- Added limit and offset variables
- Updated search result to include 'haveMore' flag
- Modified fetchResultData function to handle updated search results
This commit is contained in:
Nikita Galaiko 2023-03-23 16:11:08 +01:00
parent b7e5e2a0c8
commit a686f64c7a

View File

@ -12,7 +12,9 @@
export let data: PageData;
const { project } = data;
const limit = 50;
const query = derived(page, (page) => page.url.searchParams.get('q'));
const offset = derived(page, (page) => parseInt(page.url.searchParams.get('offset') ?? '0'));
const fetchResultData = async ({
sessionId,
@ -36,12 +38,13 @@
};
const { store: searchResults, state: searchState } = asyncDerived(
[query, project],
async ([query, project]) => {
if (!query || !project) return { page: [], total: 0 };
const results = await search({ projectId: project.id, query, limit: 50 });
[query, project, offset],
async ([query, project, offset]) => {
if (!query || !project) return { page: [], total: 0, haveMore: false };
const results = await search({ projectId: project.id, query, limit, offset });
return {
page: await Promise.all(results.page.map(fetchResultData)),
haveMore: offset + limit < results.total,
total: results.total
};
},