diff --git a/src/components/recommendations/LectureRecommendationsCard.tsx b/src/components/recommendations/LectureRecommendationsCard.tsx index a583fe2..c3d2722 100644 --- a/src/components/recommendations/LectureRecommendationsCard.tsx +++ b/src/components/recommendations/LectureRecommendationsCard.tsx @@ -34,11 +34,6 @@ export default function LectureRecommendationsCard({ lecture }: Props) { {channel}

-
-

- {description} -

-
{review_count > 0 && ( (null); - const nextRef = useRef(null); - const [swiper, setSwiper] = useState(); - const [currPageIdx, setCurrPageIdx] = useState(1); - const [isFirstSlide, setIsFirstSlide] = useState(true); - const [isLastSlide, setIsLastSlide] = useState(false); - const { data } = useQuery( [QueryKeys.RECCOMENDATION], fetchLectureRecommendations, @@ -36,84 +18,13 @@ export default function LectureRecommendationsList() { } ); - const { recommendations } = data || { recommendations: [] }; - - const slidesPerView = - windowSize.width < RECOMMENDATION_BREAKPOINT_SM ? 1 : windowSize.width < RECOMMENDATION_BREAKPOINT_LG ? 2 : 3; - const totalPage = - recommendations.length - (slidesPerView - 1) > 0 - ? recommendations.length - (slidesPerView - 1) - : 1; - - useEffect(() => { - if (currPageIdx === totalPage) { - setIsLastSlide(true); - } else { - setIsLastSlide(false); - } - if (currPageIdx === 1) { - setIsFirstSlide(true); - } else { - setIsFirstSlide(false); - } - }, [totalPage, currPageIdx]); + const general_recommendations = data?.general_recommendations ?? []; + const channel_recommendations = data?.channel_recommendations ?? []; return ( <> - {recommendations.length > 0 && ( -
- -
- { - setSwiper(swiper); - }} - onSlideChange={(swiper) => { - setCurrPageIdx(() => swiper.activeIndex + 1); - }} - > - {recommendations.map((lecture) => ( - -
{ - router.refresh(); - router.push(`/search/${lecture.lecture_code}`); - }} - > - -
-
- ))} -
-
- swiper?.slidePrev()} - disabled={isFirstSlide} - navigation='prev' - /> -
- - {currPageIdx} / {totalPage} - -
- swiper?.slideNext()} - navigation='next' - /> -
-
-
- )} + + ); } diff --git a/src/components/recommendations/channel/ChannelRecommendationsList.tsx b/src/components/recommendations/channel/ChannelRecommendationsList.tsx new file mode 100644 index 0000000..830c9f2 --- /dev/null +++ b/src/components/recommendations/channel/ChannelRecommendationsList.tsx @@ -0,0 +1,113 @@ +'use client'; +import { Swiper, SwiperSlide } from 'swiper/react'; +import SwiperCore from 'swiper'; +import 'swiper/css'; +import 'swiper/css/mousewheel'; +import SectionHeading from '../../ui/SectionHeading'; +import LectureRecommendationsCard from './../LectureRecommendationsCard'; +import useWindowSize from '@/src/hooks/useWindowSize'; +import SwiperNavigationButton from '../../ui/button/SwiperNavigationButton'; +import { useEffect, useRef, useState } from 'react'; +import { useRouter } from 'next/navigation'; +import { + RECOMMENDATION_BREAKPOINT_LG, + RECOMMENDATION_BREAKPOINT_SM +} from '@/src/constants/window/window'; + +type Props= { + recommendations: PersonalizedLecture[]; +} +export default function ChannelRecommendationsList({recommendations}: Props) { + const windowSize = useWindowSize(); + const router = useRouter(); + const prevRef = useRef(null); + const nextRef = useRef(null); + const [swiper, setSwiper] = useState(); + const [currPageIdx, setCurrPageIdx] = useState(1); + const [isFirstSlide, setIsFirstSlide] = useState(true); + const [isLastSlide, setIsLastSlide] = useState(false); + + const slidesPerView = + windowSize.width < RECOMMENDATION_BREAKPOINT_SM + ? 1 + : windowSize.width < RECOMMENDATION_BREAKPOINT_LG + ? 2 + : 3; + + const totalPage = + recommendations.length - (slidesPerView - 1) > 0 + ? recommendations.length - (slidesPerView - 1) + : 1; + + useEffect(() => { + if (currPageIdx === totalPage) { + setIsLastSlide(true); + } else { + setIsLastSlide(false); + } + if (currPageIdx === 1) { + setIsFirstSlide(true); + } else { + setIsFirstSlide(false); + } + }, [totalPage, currPageIdx]); + + return ( + <> + {recommendations.length > 0 && ( +
+ +
+ { + setSwiper(swiper); + }} + onSlideChange={(swiper) => { + setCurrPageIdx(() => swiper.activeIndex + 1); + }} + > + {recommendations.map((lecture) => ( + +
{ + router.refresh(); + router.push(`/search/${lecture.lecture_code}`); + }} + > + +
+
+ ))} +
+
+ swiper?.slidePrev()} + disabled={isFirstSlide} + navigation='prev' + /> +
+ + {currPageIdx} / {totalPage} + +
+ swiper?.slideNext()} + navigation='next' + /> +
+
+
+ )} + + ); +} diff --git a/src/components/recommendations/general/GeneralRecommendationsList.tsx b/src/components/recommendations/general/GeneralRecommendationsList.tsx new file mode 100644 index 0000000..16009c3 --- /dev/null +++ b/src/components/recommendations/general/GeneralRecommendationsList.tsx @@ -0,0 +1,113 @@ +'use client'; +import { Swiper, SwiperSlide } from 'swiper/react'; +import SwiperCore from 'swiper'; +import 'swiper/css'; +import 'swiper/css/mousewheel'; +import SectionHeading from '../../ui/SectionHeading'; +import LectureRecommendationsCard from './../LectureRecommendationsCard'; +import useWindowSize from '@/src/hooks/useWindowSize'; +import SwiperNavigationButton from '../../ui/button/SwiperNavigationButton'; +import { useEffect, useRef, useState } from 'react'; +import { useRouter } from 'next/navigation'; +import { + RECOMMENDATION_BREAKPOINT_LG, + RECOMMENDATION_BREAKPOINT_SM +} from '@/src/constants/window/window'; + +type Props = { + recommendations: PersonalizedLecture[]; +}; +export default function GeneralRecommendationsList({ recommendations }: Props) { + const windowSize = useWindowSize(); + const router = useRouter(); + const prevRef = useRef(null); + const nextRef = useRef(null); + const [swiper, setSwiper] = useState(); + const [currPageIdx, setCurrPageIdx] = useState(1); + const [isFirstSlide, setIsFirstSlide] = useState(true); + const [isLastSlide, setIsLastSlide] = useState(false); + + const slidesPerView = + windowSize.width < RECOMMENDATION_BREAKPOINT_SM + ? 1 + : windowSize.width < RECOMMENDATION_BREAKPOINT_LG + ? 2 + : 3; + + const totalPage = + recommendations.length - (slidesPerView - 1) > 0 + ? recommendations.length - (slidesPerView - 1) + : 1; + + useEffect(() => { + if (currPageIdx === totalPage) { + setIsLastSlide(true); + } else { + setIsLastSlide(false); + } + if (currPageIdx === 1) { + setIsFirstSlide(true); + } else { + setIsFirstSlide(false); + } + }, [totalPage, currPageIdx]); + + return ( + <> + {recommendations.length > 0 && ( +
+ +
+ { + setSwiper(swiper); + }} + onSlideChange={(swiper) => { + setCurrPageIdx(() => swiper.activeIndex + 1); + }} + > + {recommendations.map((lecture) => ( + +
{ + router.refresh(); + router.push(`/search/${lecture.lecture_code}`); + }} + > + +
+
+ ))} +
+
+ swiper?.slidePrev()} + disabled={isFirstSlide} + navigation='prev' + /> +
+ + {currPageIdx} / {totalPage} + +
+ swiper?.slideNext()} + navigation='next' + /> +
+
+
+ )} + + ); +}