diff --git a/frontend/src/components/Header.tsx b/frontend/src/components/Header.tsx index affabf2..b517301 100644 --- a/frontend/src/components/Header.tsx +++ b/frontend/src/components/Header.tsx @@ -4,7 +4,13 @@ import SearchIcon from "@mui/icons-material/Search"; import { SignUp, SignIn } from "@src/components"; import logo from "@src/assets/logo.jpg"; -const Header = () => { +type PropTypes = { + search: string; + handleSearch: (event: React.ChangeEvent) => void; + handleSubmit: () => void; +}; + +const Header = ({ search, handleSearch, handleSubmit }: PropTypes) => { const signInRef = useRef(null); const signUpRef = useRef(null); const [signInOpen, setSignInOpen] = useState(false); @@ -26,11 +32,12 @@ const Header = () => { > - - + + 검색 diff --git a/frontend/src/components/WebtoonList.tsx b/frontend/src/components/WebtoonList.tsx index e33ea23..867b870 100644 --- a/frontend/src/components/WebtoonList.tsx +++ b/frontend/src/components/WebtoonList.tsx @@ -3,45 +3,14 @@ import { Grid, Paper, Typography, Link, Box, Stack } from "@mui/material"; import { WebtoonBase } from "@src/types"; import axios from "axios"; -const WebtoonList = () => { - const [webtoons, setWebtoons] = useState([]); - const lastWebtoonRef = useRef(null); - const [page, setPage] = useState(1); - const [totalPage, setTotalPage] = useState(1); - - const fetchData = async (): Promise => { - try { - const response = await axios.get<{ - info: { totalPage: number; page: number }; - data: WebtoonBase[]; - }>(`http://localhost:3001/webtoon/list?page=${page}`); - const data = response.data; - setTotalPage(data.info.totalPage); - setWebtoons([...webtoons, ...data.data]); - } catch (error) { - console.log(error); - } - }; - - useEffect(() => { - void fetchData(); - }, [page]); - - useEffect(() => { - const observer = new IntersectionObserver((entries, observer) => { - if (entries[0].isIntersecting && page <= totalPage) { - observer.unobserve(lastWebtoonRef.current as HTMLElement); - setPage((page) => page + 1); - observer.observe(lastWebtoonRef.current as HTMLElement); - } - }); - observer.observe(lastWebtoonRef.current as HTMLElement); - return () => observer.disconnect(); - }, []); +type PropTypes = { + webtoons: WebtoonBase[]; +}; +const WebtoonList = ({ webtoons }: PropTypes) => { return ( - {webtoons.map((webtoon, index, array) => ( + {webtoons.map((webtoon, index) => ( @@ -54,7 +23,6 @@ const WebtoonList = () => { ))} - ); }; diff --git a/frontend/src/pages/MainPage.tsx b/frontend/src/pages/MainPage.tsx index 84216cc..7aa09ea 100644 --- a/frontend/src/pages/MainPage.tsx +++ b/frontend/src/pages/MainPage.tsx @@ -9,6 +9,19 @@ import { WebtoonBase } from "@src/types"; const Main = () => { const [platform, setPlatform] = useState("all"); const [dayOfWeeks, setDayOfWeeks] = useState([]); + const [search, setSearch] = useState(""); + const [webtoons, setWebtoons] = useState([]); + const [page, setPage] = useState(1); + const [totalPage, setTotalPage] = useState(1); + const lastWebtoonRef = useRef(null); + + const handleSubmit = () => { + void fetchData(platform); + }; + + const handleSearch = (event: React.ChangeEvent) => { + setSearch(event.target.value); + }; const handlePlatform = (event: React.SyntheticEvent, value: PlatformKind) => { setPlatform(value); @@ -18,10 +31,53 @@ const Main = () => { setDayOfWeeks([...dayOfWeeks, event.target.name as DayOfWeekKind]); }; + const fetchData = async ( + platform = undefined, + dayOfWeeks = undefined, + tags = undefined, + isEnd = undefined + ): Promise => { + try { + const response = await axios.get<{ + info: { totalPage: number; page: number }; + data: WebtoonBase[]; + }>(`http://localhost:3001/webtoon/list?page=${page}`, { + params: { + platform, + dayOfWeeks, + tags, + isEnd, + }, + }); + const data = response.data; + setTotalPage(data.info.totalPage); + setWebtoons([...webtoons, ...data.data]); + } catch (error) { + console.log(error); + } + }; + + useEffect(() => { + void fetchData(); + }, [page]); + + useEffect(() => { + console.log("check"); + const observer = new IntersectionObserver((entries, observer) => { + if (entries[0].isIntersecting && page <= totalPage) { + observer.unobserve(lastWebtoonRef.current as HTMLElement); + setPage((page) => page + 1); + observer.observe(lastWebtoonRef.current as HTMLElement); + } + }); + observer.observe(lastWebtoonRef.current as HTMLElement); + return () => observer.disconnect(); + }, []); + return ( -
+
@@ -34,7 +90,10 @@ const Main = () => { - + + + +