Skip to content

Commit

Permalink
Merge pull request #130 from gn00py48/feature/#34
Browse files Browse the repository at this point in the history
[Fix] Feature/#34 검색 기능 초기화 및 오류 메세지
  • Loading branch information
gn00py48 authored Oct 6, 2024
2 parents d592293 + 951c093 commit b55c19f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 89 deletions.
13 changes: 10 additions & 3 deletions src/components/searchBar/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as S from "./SearchBarStyle";
import searchIcon from "../../assets/images/searchIcon.svg";
import { useBoothData } from "../../hook/useBooth"; // boothpage.jsx와 동일한 방식으로 데이터 훅 사용

export const SearchBar = ({ setFilteredData }) => {
export const SearchBar = ({ setFilteredData, setIsSearchExecuted }) => {
const [searchWord, setSearchWord] = useState(""); // 검색어 입력 상태 관리

const handleInput = (e) => {
Expand All @@ -19,9 +19,15 @@ export const SearchBar = ({ setFilteredData }) => {
});

const combinedBoothData = [...(boothData1 || []), ...(boothData2 || [])];

// 검색어를 통해 부스 데이터를 필터링
const handleSearch = () => {
if (!searchWord) return;
setIsSearchExecuted(true); // 검색이 실행되면 상태를 true로 변경

if (!searchWord.trim()) {
setFilteredData(combinedBoothData); // 모든 부스를 다시 설정
return;
}

const filteredData = combinedBoothData?.filter(
(booth) =>
Expand All @@ -33,9 +39,10 @@ export const SearchBar = ({ setFilteredData }) => {
setFilteredData(filteredData);
} else {
console.log("검색 결과가 없습니다.");
setFilteredData([]);
setFilteredData([]); // 검색 결과가 없을 경우 빈 배열로 설정
}
};

const handleKeyPress = (e) => {
if (e.key === "Enter") {
handleSearch();
Expand Down
Loading

0 comments on commit b55c19f

Please sign in to comment.