Skip to content

Commit 6daa202

Browse files
authored
Merge pull request #299 from imi21123/test
Feat: 축제 부스 검색 페이지 제작
2 parents c78bcff + 17113d5 commit 6daa202

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

src/App.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import PaymentFailPage from "./pages/PaymentPage/Redirect/PaymentFailPage";
3131
import PaymentLoadingPage from "./pages/PaymentPage/Redirect/PaymentLoadingPage";
3232
import Splash from "./pages/Splash/Splash";
3333
import StoreSearchPage from "./pages/StoreSearch/StoreSearch";
34+
import FestivalBoothSearch from "./pages/StoreSearch/FestivalBoothSearch";
3435
function App() {
3536
// const [cookies, , removeCookies] = useCookies();
3637
// const [isAuth, setIsAuth] = useRecoilState(isAuthenticatedState);
@@ -163,6 +164,9 @@ function App() {
163164
/>
164165
{/* 결제 실패 리다이렉트 페이지 */}
165166
<Route path="/payment/fail" element={<NewPaymentFailPage />} />
167+
168+
{/* 축제 부스 검색 페이지 */}
169+
<Route path="/booth" element={<FestivalBoothSearch />} />
166170
</Routes>
167171
</Suspense>
168172
</RecoilRoot>

src/components/views/StoreList/StoreList.jsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@ import { IMAGES } from "../../../constants/images";
44
import { useNavigate } from "react-router-dom";
55
import useFetchSearch from "../../../hooks/useFetchSearch";
66

7-
const StoreList = ({ searchTerm = "" }) => {
7+
const StoreList = ({ searchTerm = "", cafe = false, booth = false }) => {
88
const navigate = useNavigate();
99
const stores = useFetchSearch();
10+
let displayStores = [];
1011

12+
if (cafe) {
13+
displayStores = stores.filter((item) => item.idx < 5);
14+
} else if (booth) {
15+
displayStores = stores.filter((item) => item.idx >= 5);
16+
}
1117
// 검색어에 따라 필터링된 목록을 반환하는 로직
1218
const filteredStores = stores.filter((item) => {
1319
return item.name.toLowerCase().includes(searchTerm.toLowerCase());
1420
});
1521

1622
// 검색어가 있을 경우 filteredStores를 사용하고, 없을 경우 기존 stores를 사용
17-
const displayStores = searchTerm ? filteredStores : stores;
23+
displayStores = searchTerm ? filteredStores : displayStores;
1824

1925
return (
2026
<div className="store_list">
2127
{displayStores.map((item) => (
2228
<div
2329
key={item.idx}
2430
className="store_list_item"
25-
onClick={() => navigate(`/packagingStatus?storeId=${item.idx}`)}
31+
onClick={() => {
32+
if (item.idx >= 5) {
33+
navigate(`/packagingStatus?storeId=${item.idx}&inout=2`);
34+
} else {
35+
navigate(`/packagingStatus?storeId=${item.idx}`);
36+
}
37+
}}
2638
>
2739
<img
2840
src={item.imgUrl}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, { useState, useEffect, useRef } from "react";
2+
import { IMAGES } from "../../constants/images";
3+
import "./StoreSearch.css";
4+
import Header from "../../components/views/Header/Header";
5+
import NavBar from "../../components/views/NavBar/NavBar";
6+
import StoreList from "../../components/views/StoreList/StoreList";
7+
8+
function FestivalBoothSearch() {
9+
const [searchTerm, setSearchTerm] = useState("");
10+
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm);
11+
const debounceDelay = 500; // 디바운스 지연 시간
12+
const inputRef = useRef(null);
13+
14+
// 사용자 입력 처리
15+
const handleInputChange = (e) => {
16+
setSearchTerm(e.target.value);
17+
// console.log("검색어:", searchTerm);
18+
};
19+
20+
// 디바운싱 구현
21+
useEffect(() => {
22+
const handler = setTimeout(() => {
23+
setDebouncedSearchTerm(searchTerm);
24+
console.log("디바운싱:", searchTerm);
25+
}, debounceDelay);
26+
27+
// 컴포넌트가 unmount되거나 다음 useEffect가 실행되기 전에 타이머를 정리
28+
return () => {
29+
clearTimeout(handler);
30+
};
31+
}, [searchTerm, debounceDelay]);
32+
33+
return (
34+
<div className="store_search">
35+
<Header headerProps={{ pageName: "축제 주점 검색" }} />
36+
37+
<form className="store_search_form" onSubmit={(e) => e.preventDefault()}>
38+
<img src={IMAGES.search} alt="search" />
39+
<input
40+
type="text"
41+
className="store_search_input"
42+
placeholder="Search"
43+
value={searchTerm}
44+
onChange={handleInputChange}
45+
ref={inputRef}
46+
/>
47+
</form>
48+
49+
{/* Debounced search term을 사용하여 StoreList에 prop으로 전달 */}
50+
<StoreList searchTerm={debouncedSearchTerm} booth={true} />
51+
52+
<NavBar />
53+
</div>
54+
);
55+
}
56+
57+
export default FestivalBoothSearch;

src/pages/StoreSearch/StoreSearch.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function StoreSearch() {
4747
</form>
4848

4949
{/* Debounced search term을 사용하여 StoreList에 prop으로 전달 */}
50-
<StoreList searchTerm={debouncedSearchTerm} />
50+
<StoreList searchTerm={debouncedSearchTerm} cafe={true} />
5151

5252
<NavBar />
5353
</div>

0 commit comments

Comments
 (0)