From 390fbf6cdcfe1f3eb7f768537c816debad214296 Mon Sep 17 00:00:00 2001 From: wslyvh Date: Mon, 18 Nov 2024 14:36:03 +0700 Subject: [PATCH] archive qs --- devcon-archive/src/hooks/useArchiveSearch.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/devcon-archive/src/hooks/useArchiveSearch.ts b/devcon-archive/src/hooks/useArchiveSearch.ts index 0cd4982b..b65bcb67 100644 --- a/devcon-archive/src/hooks/useArchiveSearch.ts +++ b/devcon-archive/src/hooks/useArchiveSearch.ts @@ -20,13 +20,15 @@ const fetcher = async (url: string) => { export const useArchiveSearch = (qs: string, params?: SearchParams): FetchedResult> => { const defaultData = { total: 0, currentPage: 0, items: [] } const [data, setData] = useState>(defaultData) - let uri = `https://api.devcon.org/sessions?event=devcon-6&event=devcon-5&event=devcon-4&event=devcon-3&event=devcon-2&event=devcon-1&event=devcon-0` - if (qs) uri += qs.replace('?', '&') + let uri = `https://api.devcon.org/sessions${qs}` + if (!qs) uri += '?' if (params?.q) uri += `&q=${params.q}` if (params?.from) uri += `&from=${params.from}` if (params?.size) uri += `&size=${params.size}` if (params?.sort) uri += `&sort=${params.sort}` if (params?.order) uri += `&order=${params.order}` + if (!uri.includes('event=')) + uri += `&event=devcon-6&event=devcon-5&event=devcon-4&event=devcon-3&event=devcon-2&event=devcon-1&event=devcon-0` const { error, isValidating } = useSWR(uri, fetcher, { onSuccess: data => {