Added sort option to the UI

This commit is contained in:
Luis Alvarez
2020-10-14 11:50:38 -05:00
parent 398feac176
commit cdb2cbdebd
2 changed files with 7 additions and 3 deletions

View File

@@ -12,11 +12,12 @@ export type SearchProductsInput = {
search?: string
categoryId?: number
brandId?: number
sort?: string
}
export const fetcher: HookFetcher<SearchProductsData, SearchProductsInput> = (
options,
{ search, categoryId, brandId },
{ search, categoryId, brandId, sort },
fetch
) => {
// Use a dummy base as we only care about the relative path
@@ -27,6 +28,7 @@ export const fetcher: HookFetcher<SearchProductsData, SearchProductsInput> = (
url.searchParams.set('category', String(categoryId))
if (Number.isInteger(categoryId))
url.searchParams.set('brand', String(brandId))
if (sort) url.searchParams.set('sort', sort)
return fetch({
url: url.pathname + url.search,
@@ -45,6 +47,7 @@ export function extendHook(
['search', input.search],
['categoryId', input.categoryId],
['brandId', input.brandId],
['sort', input.sort],
],
customFetcher,
{ revalidateOnFocus: false, ...swrOptions }