Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 1x 3x 3x 3x 3x 3x 3x | import { useMemo } from "react";
import { CatalogSearchSort } from "../../api/catalog-search/constants";
import { CDKType } from "../../constants/constructs";
import { Language } from "../../constants/languages";
import { usePagination } from "../usePagination";
import { useSearch } from "../useSearch";
export interface UseCatalogResultsOptions {
cdkMajor?: number;
cdkType?: CDKType;
keywords?: string[];
limit: number;
offset?: number;
query?: string;
language?: Language | null;
languages?: Language[];
sort?: CatalogSearchSort;
tags?: string[];
}
/**
* A hook to wrap `useSearch` results with pagination and parameter memoization
* This hook depends on an upstream provider - `<SearchProvider />`, which wraps all pages.
*/
export const useCatalogResults = ({
cdkMajor,
cdkType,
keywords,
limit,
offset = 0,
query = "",
language = null,
languages,
sort,
tags,
}: UseCatalogResultsOptions) => {
const filters = useMemo(
() => ({
cdkMajor,
cdkType,
keywords,
language: language ?? undefined,
languages,
tags,
}),
[cdkMajor, cdkType, keywords, language, languages, tags]
);
const results = useSearch({
filters,
query,
sort,
});
const { page, pageLimit } = usePagination(results, {
offset,
limit,
});
return useMemo(
() => ({ results, page, pageLimit }),
[page, pageLimit, results]
);
};
|