From 315dc427da68c02fb8ba7e09aa097c2348dc5f46 Mon Sep 17 00:00:00 2001 From: novice0840 Date: Mon, 6 Nov 2023 22:22:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9B=B9=ED=88=B0=20=ED=94=8C=EB=9E=AB?= =?UTF-8?q?=ED=8F=BC=20=EC=84=A0=ED=83=9D=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Platforms.tsx | 52 +++++++++++---- frontend/src/pages/MainPage.tsx | 91 ++------------------------- 2 files changed, 46 insertions(+), 97 deletions(-) diff --git a/frontend/src/components/Platforms.tsx b/frontend/src/components/Platforms.tsx index 4676bda..4b7b66f 100644 --- a/frontend/src/components/Platforms.tsx +++ b/frontend/src/components/Platforms.tsx @@ -1,22 +1,50 @@ import React from "react"; -import { Tabs, Tab } from "@mui/material"; +import { Checkbox, FormLabel, FormGroup, FormControl, FormControlLabel } from "@mui/material"; import { PlatformKind } from "@src/types"; type PropTypes = { - platform: PlatformKind; - handlePlatform: (event: React.SyntheticEvent, value: PlatformKind) => void; + handleDayOfWeek: (event: React.ChangeEvent) => void; }; -const Platforms = ({ platform, handlePlatform }: PropTypes) => { +const Platforms = ({ handleDayOfWeek }: PropTypes) => { return ( - - - - - - - - + + 요일 + + } + label="월요웹툰" + /> + } + label="화요웹툰" + /> + } + label="수요웹툰" + /> + } + label="목요웹툰" + /> + } + label="금요웹툰" + /> + } + label="토요웹툰" + /> + } + label="일요웹툰" + /> + } + label="완결웹툰" + /> + + ); }; diff --git a/frontend/src/pages/MainPage.tsx b/frontend/src/pages/MainPage.tsx index 598e82d..33b0ae7 100644 --- a/frontend/src/pages/MainPage.tsx +++ b/frontend/src/pages/MainPage.tsx @@ -8,98 +8,19 @@ import { WebtoonBase } from "@src/types"; import { useNavigate, redirect, useLocation } from "react-router-dom"; const MainPage = () => { - const [platform, setPlatform] = useState("all"); - const [dayOfWeeks, setDayOfWeeks] = useState([]); - const [search, setSearch] = useState(""); + const [category, setCategory] = useState({ + platform: "all", + dayOfWeeks: [], + genres: [], + }); const [webtoons, setWebtoons] = useState([]); - const [page, setPage] = useState(1); - const [totalPage, setTotalPage] = useState(1); const lastWebtoonRef = useRef(null); const navigate = useNavigate(); - const location = useLocation(); - - const handleSubmit = () => { - console.log("submit click"); - }; - - const handleSearch = (event: React.ChangeEvent) => { - setSearch(event.target.value); - }; - - const handlePlatform = (event: React.SyntheticEvent, value: PlatformKind) => { - setPlatform(value); - if (value === "all") navigate("?platform=all"); - else { - navigate(`?platform=${value}`); - } - }; const handleDayOfWeek = (event: React.ChangeEvent) => { const newDay = event.target.name as DayOfWeekKind; - if (dayOfWeeks.includes(newDay)) { - setDayOfWeeks(dayOfWeeks.filter((day) => day !== newDay)); - } else { - setDayOfWeeks([...dayOfWeeks, newDay]); - } }; - const fetchDatainit = async (): Promise => { - const params: { platform?: string; days?: string } = {}; - if (platform !== "all") params.platform = platform; - if (dayOfWeeks.length !== 0) params.days = dayOfWeeks.join(","); - try { - const response = await axios.get<{ - info: { totalPage: number; page: number }; - data: WebtoonBase[]; - }>(`http://localhost:3001/webtoon/list?page=${page}`, { params }); - const data = response.data; - setPage(1); - setTotalPage(data.info.totalPage); - setWebtoons([...data.data]); - } catch (error) { - console.log(error); - } - }; - - const fetchDataPlus = async (): Promise => { - const params: { platform?: string; days?: string } = {}; - if (platform !== "all") params.platform = platform; - if (dayOfWeeks.length !== 0) params.days = dayOfWeeks.join(","); - try { - const response = await axios.get<{ - info: { totalPage: number; page: number }; - data: WebtoonBase[]; - }>(`http://localhost:3001/webtoon/list?page=${page}`, { params }); - const data = response.data; - setTotalPage(data.info.totalPage); - setWebtoons([...webtoons, ...data.data]); - } catch (error) { - console.log(error); - } - }; - - useEffect(() => { - const observer = new IntersectionObserver((entries, observer) => { - if (entries[0].isIntersecting && page <= totalPage) { - observer.unobserve(lastWebtoonRef.current as HTMLElement); - console.log("check"); - setPage((page) => page + 1); - observer.observe(lastWebtoonRef.current as HTMLElement); - } - }); - observer.observe(lastWebtoonRef.current as HTMLElement); - return () => observer.disconnect(); - }, [totalPage]); - - useEffect(() => { - void fetchDatainit(); - }, [platform, dayOfWeeks]); - - useEffect(() => { - console.log("page changed"); - void fetchDataPlus(); - }, [page]); - return ( @@ -107,7 +28,7 @@ const MainPage = () => { - +