aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/recherche
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-13 12:37:50 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-13 15:36:38 +0100
commit599b70cd2390d08ce26ee44174b3f39c6587110c (patch)
tree15d967fc142bf632df3dd55df373bfd4e33d2d90 /src/pages/recherche
parentd7bcd93efcd4f1ae20678d0efa6777cfadc09a4e (diff)
refactor(hooks): rewrite usePagination hook
* replace `isLoadingInitialData` with `isLoading` & `isRefreshing` * rename `fallbackData` prop to `fallback` * replace `setSize` return with a `loadMore` callback * add tests
Diffstat (limited to 'src/pages/recherche')
-rw-r--r--src/pages/recherche/index.tsx19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx
index 12a482d..a0e5057 100644
--- a/src/pages/recherche/index.tsx
+++ b/src/pages/recherche/index.tsx
@@ -3,7 +3,6 @@ import type { GetStaticProps } from 'next';
import Head from 'next/head';
import { useRouter } from 'next/router';
import Script from 'next/script';
-import { useCallback } from 'react';
import { useIntl } from 'react-intl';
import {
getLayout,
@@ -119,15 +118,16 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({
const {
data,
error,
- isLoadingInitialData,
+ isLoading,
isLoadingMore,
+ isRefreshing,
hasNextPage,
- setSize,
+ loadMore,
} = usePagination<RawArticle>({
- fallbackData: [],
+ fallback: [],
fetcher: getArticles,
perPage: blog.postsPerPage,
- search: query.s as string,
+ searchQuery: query.s as string,
});
const totalArticles = useDataFromAPI<number>(async () =>
@@ -156,13 +156,6 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({
]
: [];
- /**
- * Load more posts handler.
- */
- const loadMore = useCallback(() => {
- setSize((prevSize) => prevSize + 1);
- }, [setSize]);
-
const thematicsListTitle = intl.formatMessage({
defaultMessage: 'Thematics',
description: 'SearchPage: thematics list widget title',
@@ -238,7 +231,7 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({
<PostsList
baseUrl={postsListBaseUrl}
byYear={true}
- isLoading={isLoadingMore ?? isLoadingInitialData}
+ isLoading={isLoading || isLoadingMore || isRefreshing}
loadMore={loadMore}
posts={getPostsList(data)}
showLoadMoreBtn={hasNextPage}