diff --git a/src/app/page.tsx b/src/app/page.tsx index 533a6b9..3a80cbc 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,17 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable no-console */ +/* eslint-disable @typescript-eslint/no-floating-promises */ + +'use client'; + +import { useEffect, useRef, useState } from 'react'; + import classNames from 'classnames/bind'; +import { useRouter } from 'next/navigation'; +import Flex from '@/components/shared/flex/Flex'; +import HomeSearchBar from '@/components/shared/home-search-bar/HomeSearchBar'; +import ImgToText from '@/components/shared/ocr/OCR'; import ProductList from '@components/home/product-list/ProductList'; import { MOCK_BANNER_DATA } from '@mocks/homeHandler/mocks'; // import { TEST_MOCK_BANNER_DATA } from '@mocks/homeHandler/mocks'; @@ -16,6 +28,30 @@ import styles from './page.module.scss'; const cx = classNames.bind(styles); function Home() { + useEffect(() => { + const fetchData = async () => { + try { + const { Img } = await ImgToText(); + const text = await Img(); + console.log(text); + } catch (error) { + console.error(error); + } + }; + + fetchData(); + }, []); + + const keywordRef = useRef(null); + const router = useRouter(); + // const [trigger, setTrigger] = useState(false); + // useEffect(() => { + // Img(); + // }, []); + const handleSearch = () => { + router.push(`/search?keyword=${keywordRef.current?.value}`); + }; + return ( <>
@@ -24,6 +60,11 @@ function Home() { {/* */}
+ + + + + 추천 세차용품 diff --git a/src/app/search/page.tsx b/src/app/search/page.tsx index 3c02822..28339ad 100644 --- a/src/app/search/page.tsx +++ b/src/app/search/page.tsx @@ -1,12 +1,14 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable react-hooks/exhaustive-deps */ 'use client'; -import { useRef, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { useForm } from 'react-hook-form'; import InfiniteScroll from 'react-infinite-scroll-component'; import classNames from 'classnames/bind'; +import { useSearchParams, useRouter } from 'next/navigation'; import { SEARCH_FILTER_MAP, SearchFilterType } from '@constants/searchByMap'; import useSearchProductByFilter from '@remote/queries/search/useSearchProductByFilter'; @@ -30,13 +32,27 @@ const options = [ ]; function SearchPage() { + const router = useRouter(); + const searchParams = useSearchParams(); + const getItem = searchParams.get('keyword') as string; + const keywordRef = useRef(null); const [trigger, setTrigger] = useState(false); const handleSearch = () => { - setTrigger((prev) => { return !prev; }); + setTrigger((prev) => { + return !prev; + }); }; + useEffect(() => { + if (keywordRef.current) { + // router.push(`/search?keyword=${keywordRef.current.value}`); + keywordRef.current.value = getItem; + handleSearch(); + } + }, []); + const { register, watch } = useForm({ defaultValues: { filter: 'viewCnt-order', @@ -46,7 +62,9 @@ function SearchPage() { const [isOpenFilterDrawer, setIsOpenFilterDrawer] = useState(false); const handleFilterClick = () => { - setIsOpenFilterDrawer((prev) => { return !prev; }); + setIsOpenFilterDrawer((prev) => { + return !prev; + }); }; // @@ -55,7 +73,10 @@ function SearchPage() { hasNextPage, loadMore, productCount, - } = useSearchProductByFilter(keywordRef.current?.value, watch('filter') as SearchFilterType); + } = useSearchProductByFilter( + keywordRef.current?.value, + watch('filter') as SearchFilterType, + ); return ( <> @@ -67,7 +88,9 @@ function SearchPage() { {`총 ${productCount}개`} @@ -76,7 +99,11 @@ function SearchPage() { dataLength={productList?.length ?? 0} next={loadMore} hasMore={hasNextPage} - loader={
Loading ...
} + loader={( +
+ Loading ... +
+ )} inverse={false} style={{ overflow: 'visible' }} > @@ -87,7 +114,12 @@ function SearchPage() {
- { setIsOpenFilterDrawer(false); }}> + { + setIsOpenFilterDrawer(false); + }} + > {/* 필터 내용 아코디언 */}

Filter Content