From 8599ae2c5ac11f2818f56c9f7de7666a38b4386c Mon Sep 17 00:00:00 2001 From: zyachel Date: Sun, 21 May 2023 18:13:44 +0530 Subject: [PATCH] fix(form): fix hydration error was due to nested anchor tags --- src/components/card/CardResult.tsx | 18 +++-- src/components/forms/find/index.tsx | 66 +++++++++---------- .../components/card/card-result.module.scss | 3 - 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/components/card/CardResult.tsx b/src/components/card/CardResult.tsx index 8dfe838..aab4a66 100644 --- a/src/components/card/CardResult.tsx +++ b/src/components/card/CardResult.tsx @@ -25,16 +25,14 @@ const CardResult = ({ link, name, image, showImage, children, ...rest }: Props) ); return ( - - - -
{ImageComponent}
-
-

{name}

- {children} -
-
- + +
{ImageComponent}
+
+ + {name} + + {children} +
); }; diff --git a/src/components/forms/find/index.tsx b/src/components/forms/find/index.tsx index 36855d4..1628249 100644 --- a/src/components/forms/find/index.tsx +++ b/src/components/forms/find/index.tsx @@ -5,41 +5,16 @@ import { QueryTypes } from 'src/interfaces/shared/search'; import { resultTypes, resultTitleTypes } from 'src/utils/constants/find'; import styles from 'src/styles/modules/components/form/find.module.scss'; -/** - * helper function to render similar radio btns. saves from boilerplate. - * @param data radio btn obj - * @param parentClass class under which radio input and label will be - * @returns JSX array of radios - */ -const renderRadioBtns = ( - data: typeof resultTypes | typeof resultTitleTypes, - parentClass: string -) => { - return data.types.map(({ name, val }) => ( -

- - -

- )); -}; - type Props = { className?: string; }; -// MAIN FUNCTION const Form = ({ className }: Props) => { const router = useRouter(); const formRef = useRef(null); const [isDisabled, setIsDisabled] = useState(false); - // title types can't be selected unless type selected is 'title'. below is the logic for disabling/enabling titleTypes. + // title types can't be selected unless type selected is 'title' const typesChangeHandler: ChangeEventHandler = e => { const el = e.target as unknown as HTMLInputElement; // we have only radios that'll fire change event. const value = el.value as QueryTypes; @@ -60,6 +35,7 @@ const Form = ({ className }: Props) => { const queryStr = cleanQueryStr(entries); if (query) router.push(`/find?${queryStr}`); + else setIsDisabled(false); formEl.reset(); }; @@ -87,22 +63,20 @@ const Form = ({ className }: Props) => { name='q' placeholder='movies, people...' className={styles.searchbar__input} + required + minLength={2} />

- - Filter by Type - - {renderRadioBtns(resultTypes, styles.type)} + Filter by Type +
- - Filter by Title Type - - {renderRadioBtns(resultTitleTypes, styles.titleType)} + Filter by Title Type +

@@ -120,4 +94,28 @@ const Form = ({ className }: Props) => { ); }; +const RadioBtns = ({ + data, + className, +}: { + data: typeof resultTypes | typeof resultTitleTypes; + className: string; +}) => ( + <> + {data.types.map(({ name, val }) => ( +

+ + +

+ ))} + +); + + export default Form; diff --git a/src/styles/modules/components/card/card-result.module.scss b/src/styles/modules/components/card/card-result.module.scss index 293289a..ad794a6 100644 --- a/src/styles/modules/components/card/card-result.module.scss +++ b/src/styles/modules/components/card/card-result.module.scss @@ -7,9 +7,6 @@ display: grid; grid-template-columns: var(--width) auto; - text-decoration: none; - color: inherit; - @include helper.bp('bp-450') { --height: 15rem; grid-template-columns: auto;