diff --git a/src/Main/components/SearchContents.tsx b/src/Main/components/SearchContents.tsx index 0036301..0e02bdb 100644 --- a/src/Main/components/SearchContents.tsx +++ b/src/Main/components/SearchContents.tsx @@ -1,5 +1,183 @@ +import { useState } from "react"; +import { + Box, + Grid, + Text, + Spinner, + InputGroup, + Input, + InputRightElement, + IconButton, + Select, + useDisclosure, + Flex, + useBreakpointValue, +} from "@chakra-ui/react"; +import { SearchIcon } from "@chakra-ui/icons"; +import api from "../../api/interceptor"; +import DetailModal from "./DetailModal"; + +interface Content { + id: number; + showId: string; + type: string; + title: string; + director: string; + cast: string; + country: string; + dateAdded: string; + releaseYear: string; + rating: string; + duration: string; + listedIn: string; + description: string; +} + function SearchContents(): JSX.Element { - return
검색 콘텐츠 컴포넌트 내용
; + const [searchType, setSearchType] = useState("title"); + const [searchQuery, setSearchQuery] = useState(""); + const [searchResults, setSearchResults] = useState([]); + const [isLoading, setIsLoading] = useState(false); + const [selectedContent, setSelectedContent] = useState(null); + const { isOpen, onOpen, onClose } = useDisclosure(); + + const handleSearch = async () => { + if (!searchQuery) return; + + setIsLoading(true); + try { + const response = await api.get( + `/api/search/${searchType}/${searchQuery}` + ); + const contents = response.data.map( + (item: { content: Content }) => item.content + ); + setSearchResults(contents); + } catch (error) { + console.error("검색 요청 중 오류 발생:", error); + } finally { + setIsLoading(false); + } + }; + + const handleCardClick = (content: Content) => { + setSelectedContent(content); + onOpen(); + }; + + const handleKeyPress = (event: React.KeyboardEvent) => { + if (event.key === "Enter") { + handleSearch(); + } + }; + + const cardColumns = useBreakpointValue({ base: "1fr", md: "repeat(5, 1fr)" }); + + return ( + + {/* 검색 필터와 검색 입력창 */} + + + + + setSearchQuery(e.target.value)} + onKeyPress={handleKeyPress} + /> + + } + colorScheme="teal" + onClick={handleSearch} + size="sm" + /> + + + + + {/* 검색 결과 */} + {isLoading ? ( + + + + ) : ( + <> + {searchResults.length > 0 ? ( + + {searchResults.map((content) => ( + handleCardClick(content)} + > + + {content.title} + + + ))} + + ) : ( + + 검색 결과가 없습니다. + + )} + + )} + + {/* 상세 정보 모달 */} + + + ); } export default SearchContents;