diff --git a/components/tournament-record/LeagueButtonGroup.tsx b/components/tournament-record/LeagueButtonGroup.tsx new file mode 100644 index 000000000..6fdfca914 --- /dev/null +++ b/components/tournament-record/LeagueButtonGroup.tsx @@ -0,0 +1,40 @@ +import React, { SetStateAction, useState } from 'react'; +import styles from 'styles/tournament-record/LeagueButtonGroup.module.scss'; + +interface LeagueButtonGroupProps { + onSelect: React.Dispatch>; +} + +export default function LeagueButtonGroup({ + onSelect, +}: LeagueButtonGroupProps) { + const [activeButton, setActiveButton] = useState('ROOKIE'); + + const handleClick = (league: string) => { + onSelect(league); + setActiveButton(league); + }; + + return ( +
+ + + +
+ ); +} diff --git a/components/tournament-record/WinnerProfileImage.tsx b/components/tournament-record/WinnerProfileImage.tsx index e8243f779..5c0fff19a 100644 --- a/components/tournament-record/WinnerProfileImage.tsx +++ b/components/tournament-record/WinnerProfileImage.tsx @@ -28,7 +28,13 @@ export default function WinnerProfileImage({ }; }, [swiper, slideIndex]); - function applyStyleAndSetTournamentInfo() { + useEffect(() => { + if (indexDiff === 0) { + setTournamentInfo(tournament); + } + }, [indexDiff, tournament, setTournamentInfo]); + + function applyStyle() { if (indexDiff === 0) { setTournamentInfo(tournament); return styles.firstLayer; @@ -39,7 +45,7 @@ export default function WinnerProfileImage({ return (
-2 && indexDiff < 2 && applyStyleAndSetTournamentInfo() + indexDiff > -2 && indexDiff < 2 && applyStyle() }`} > >; } -export default function WinnerSwiper(props: WinnerSwiperProps) { - const fetchTournamentData = useCallback( - async (page: number) => { - console.log('Fetching more data...'); - const res = await mockInstance.get( - `/tournament?page=${page}&type=${props.type}&size=${props.size}` +const WinnerSwiper = forwardRef( + (props: WinnerSwiperProps, ref: Ref | undefined) => { + const fetchTournamentData = useCallback( + async (page: number) => { + console.log('Fetching more data...'); + const res = await mockInstance.get( + `/tournament?page=${page}&type=${props.type}&size=${props.size}` + ); + return res.data; + }, + [props.type, props.size] + ); + + // TODO: error, isLoading 시 return 컴포넌트 + const { data, error, isLoading, hasNextPage, fetchNextPage } = + InfiniteScroll( + ['tournamentData', props.type], + fetchTournamentData, + 'JC01' ); - return res.data; - }, - [props.type, props.size] - ); - // TODO: error, isLoading 시 return 컴포넌트 - const { data, error, isLoading, hasNextPage, fetchNextPage } = - InfiniteScroll( - 'tournamentData', - fetchTournamentData, - 'JC01' + const coverflowEffect = useMemo( + () => ({ + rotate: 35, + stretch: 0, + depth: 500, + slideShadows: true, + }), + [] + ); + + const indexChangeHandler = useCallback( + (swiper: SwiperClass) => { + const slidesLength = swiper.slides.length; + if (hasNextPage && swiper.activeIndex >= slidesLength - 3) { + fetchNextPage(); + } + }, + [hasNextPage, fetchNextPage] ); - const coverflowEffect = useMemo( - () => ({ - rotate: 35, - stretch: 0, - depth: 500, - slideShadows: true, - }), - [] - ); + return ( + + {data?.pages.map((page, pageIndex) => ( + + {page.tournaments.length > 0 && + page.tournaments.map((tournament, index) => ( + + + + ))} + + ))} + + ); + } +); - const indexChangeHandler = useCallback( - (swiper: SwiperClass) => { - const slidesLength = swiper.slides.length; - if (hasNextPage && swiper.activeIndex >= slidesLength - 3) { - fetchNextPage(); - } - }, - [hasNextPage, fetchNextPage] - ); +// forwardRef에 들어가는 익명함수에 대한 name +WinnerSwiper.displayName = 'WinnerSwiper'; - return ( - - {data?.pages.map((page, pageIndex) => ( - - {page.tournaments.length > 0 && - page.tournaments.map((tournament, index) => ( - - - - ))} - - ))} - - ); -} +export default WinnerSwiper; diff --git a/pages/tournament-record.tsx b/pages/tournament-record.tsx index 04f23755b..122866800 100644 --- a/pages/tournament-record.tsx +++ b/pages/tournament-record.tsx @@ -1,24 +1,31 @@ -import { useState } from 'react'; +import { useState, useRef, useEffect } from 'react'; +import { SwiperRef } from 'swiper/react'; import { TournamentInfo } from 'types/tournamentTypes'; +import LeagueButtonGroup from 'components/tournament-record/LeagueButtonGroup'; import WinnerSwiper from 'components/tournament-record/WinnerSwiper'; import styles from 'styles/tournament-record/TournamentRecord.module.scss'; export default function TournamentRecord() { const [tournamentInfo, setTournamentInfo] = useState(); + const [selectedType, setSelectedType] = useState('ROOKIE'); + const swiperRef = useRef(null); const endTime = tournamentInfo ? new Date(tournamentInfo.endTime) : null; + useEffect(() => { + if (swiperRef) { + swiperRef.current?.swiper.slideTo(0, 0); // index, speed + } + }, [selectedType]); + return (

명예의 전당

-
- - - -
+

{tournamentInfo?.winnerIntraId}

diff --git a/styles/tournament-record/LeagueButtonGroup.module.scss b/styles/tournament-record/LeagueButtonGroup.module.scss new file mode 100644 index 000000000..97aefe009 --- /dev/null +++ b/styles/tournament-record/LeagueButtonGroup.module.scss @@ -0,0 +1,24 @@ +.leagueButtonWrapper { + display: flex; + padding-right: 2rem; + padding-left: 2rem; + margin-top: 1.4rem; + justify-content: space-between; + + button { + width: 5rem; + height: 2rem; + font-size: 1rem; + font-weight: 400; + color: #cbcbcb; + background-color: transparent; + border-color: transparent; + + &.active { + font-weight: 700; + color: #ffffff; + border: 2px solid #9e00ff; + border-radius: 0.6rem; + } + } +} diff --git a/styles/tournament-record/TournamentRecord.module.scss b/styles/tournament-record/TournamentRecord.module.scss index f344867df..aef840cf7 100644 --- a/styles/tournament-record/TournamentRecord.module.scss +++ b/styles/tournament-record/TournamentRecord.module.scss @@ -10,22 +10,6 @@ justify-content: center; } -.leagueButtonWrapper { - display: flex; - padding-right: 1.5rem; - padding-left: 1.5rem; - margin-top: 1.4rem; - justify-content: space-between; - - button { - font-size: 1rem; - font-weight: 400; - color: #cbcbcb; - background-color: transparent; - border-color: transparent; - } -} - .winnerImageContainer { height: 10rem; margin-top: 1.8rem;