diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-03 23:03:06 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | ce4a18899f24ba89b63ef743476ec0dbf1999ecf (patch) | |
| tree | 003a59ee62bc5f1f97110926559d941a978090ac /src/pages | |
| parent | ddd45e29745b73e7fe1684e197dcff598b375644 (diff) | |
refactor(components): rewrite SearchForm component
* remove searchPage prop (the consumer should handle the submit)
* change onSubmit type
* use `useForm` hook to handle the form
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/404.tsx | 28 | ||||
| -rw-r--r-- | src/pages/blog/index.tsx | 1 | ||||
| -rw-r--r-- | src/pages/blog/page/[number].tsx | 1 | ||||
| -rw-r--r-- | src/pages/recherche/index.tsx | 1 | ||||
| -rw-r--r-- | src/pages/sujet/[slug].tsx | 1 | ||||
| -rw-r--r-- | src/pages/thematique/[slug].tsx | 1 |
6 files changed, 26 insertions, 7 deletions
diff --git a/src/pages/404.tsx b/src/pages/404.tsx index ae6eac5..00e2d5a 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -1,6 +1,8 @@ +/* eslint-disable max-statements */ import type { GetStaticProps } from 'next'; import Head from 'next/head'; -import type { ReactNode } from 'react'; +import { useRouter } from 'next/router'; +import { useCallback, type ReactNode } from 'react'; import { useIntl } from 'react-intl'; import { getLayout, @@ -9,6 +11,7 @@ import { LinksListWidget, PageLayout, SearchForm, + type SearchFormSubmit, } from '../components'; import { getThematicsPreview, @@ -39,6 +42,7 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ thematicsList, topicsList, }) => { + const router = useRouter(); const intl = useIntl(); const { website } = useSettings(); const title = intl.formatMessage({ @@ -85,6 +89,26 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ description: 'Error404Page: topics list widget title', id: 'GVpTIl', }); + const searchSubmitHandler: SearchFormSubmit = useCallback( + ({ query }) => { + if (!query) + return { + messages: { + error: intl.formatMessage({ + defaultMessage: 'Query must be longer than one character.', + description: '404Page: invalid query message', + id: 'C6oK7h', + }), + }, + validator: (value) => value.query.length > 1, + }; + + router.push({ pathname: ROUTES.SEARCH, query: { s: query } }); + + return undefined; + }, + [intl, router] + ); return ( <> @@ -134,7 +158,7 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ id: 'XKy7rx', })} </p> - <SearchForm isLabelHidden searchPage={ROUTES.SEARCH} /> + <SearchForm isLabelHidden onSubmit={searchSubmitHandler} /> </PageLayout> </> ); diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 5c64e6d..accd314 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -217,7 +217,6 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({ isLoading={isLoadingMore ?? isLoadingInitialData} loadMore={loadMore} posts={getPostsList(data)} - searchPage={ROUTES.SEARCH} showLoadMoreBtn={hasNextPage} total={totalArticles} /> diff --git a/src/pages/blog/page/[number].tsx b/src/pages/blog/page/[number].tsx index 58cf7b9..1c723f1 100644 --- a/src/pages/blog/page/[number].tsx +++ b/src/pages/blog/page/[number].tsx @@ -213,7 +213,6 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({ byYear={true} pageNumber={pageNumber} posts={getPostsList([articles])} - searchPage={ROUTES.SEARCH} total={totalArticles} /> </PageLayout> diff --git a/src/pages/recherche/index.tsx b/src/pages/recherche/index.tsx index 32312ec..12a482d 100644 --- a/src/pages/recherche/index.tsx +++ b/src/pages/recherche/index.tsx @@ -241,7 +241,6 @@ const SearchPage: NextPageWithLayout<SearchPageProps> = ({ isLoading={isLoadingMore ?? isLoadingInitialData} loadMore={loadMore} posts={getPostsList(data)} - searchPage={ROUTES.SEARCH} showLoadMoreBtn={hasNextPage} total={totalArticles ?? 0} /> diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 87c3340..9094703 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -228,7 +228,6 @@ const TopicPage: NextPageWithLayout<TopicPageProps> = ({ baseUrl={postsListBaseUrl} byYear={true} posts={getPostsWithUrl(articles)} - searchPage={ROUTES.SEARCH} titleLevel={3} total={articles.length} /> diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index 8e21ff6..bb97f47 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -200,7 +200,6 @@ const ThematicPage: NextPageWithLayout<ThematicPageProps> = ({ baseUrl={postsListBaseUrl} byYear={true} posts={getPostsWithUrl(articles)} - searchPage={ROUTES.SEARCH} titleLevel={3} total={articles.length} /> |
