From b017e8bff449982dd8cb2ea764c3a90e3b46e3aa Mon Sep 17 00:00:00 2001 From: oikkoikk Date: Wed, 25 Oct 2023 18:21:34 +0900 Subject: [PATCH] [SWM-363] Feat : wrongQuizSlider --- .../dashboard/main/MainDashboard.tsx | 7 +- .../dashboard/main/motivation/Motivation.tsx | 13 ---- .../wrongQuizReview/WrongQuizReviewCard.tsx | 60 +++++++++++++++ .../wrongQuizReview/WrongQuizReviewSlider.tsx | 75 +++++++++++++++++++ types/types.d.ts | 13 +++- 5 files changed, 150 insertions(+), 18 deletions(-) delete mode 100644 src/components/dashboard/main/motivation/Motivation.tsx create mode 100644 src/components/dashboard/main/wrongQuizReview/WrongQuizReviewCard.tsx create mode 100644 src/components/dashboard/main/wrongQuizReview/WrongQuizReviewSlider.tsx diff --git a/src/components/dashboard/main/MainDashboard.tsx b/src/components/dashboard/main/MainDashboard.tsx index 0d6692f..4d3a99c 100644 --- a/src/components/dashboard/main/MainDashboard.tsx +++ b/src/components/dashboard/main/MainDashboard.tsx @@ -1,7 +1,7 @@ import SectionHeading from '../../ui/SectionHeading'; import CompletionRate from './completionRate/CompletionRate'; import CorrectnessRate from './correctnessRate/CorrectnessRate'; -import Motivation from './motivation/Motivation'; +import WrongQuizReviewSlider from './wrongQuizReview/WrongQuizReviewSlider'; import TotalLearningTime from './totalLearningTime/TotalLearningTime'; import WeeklyCalendar from './weeklyCalendar/WeeklyCalendar'; @@ -14,10 +14,11 @@ export default async function MainDashboard({ dashboardInfo }: Props) { completion_rate, correctness_rate, motivation, + wrong_quizzes, total_learning_time, learning_histories } = dashboardInfo; - + return (
- + diff --git a/src/components/dashboard/main/motivation/Motivation.tsx b/src/components/dashboard/main/motivation/Motivation.tsx deleted file mode 100644 index c0b91a1..0000000 --- a/src/components/dashboard/main/motivation/Motivation.tsx +++ /dev/null @@ -1,13 +0,0 @@ -type Props = { - text: string; -}; - -export default function Motivation({ text }: Props) { - return ( -
-

- {text} -

-
- ); -} diff --git a/src/components/dashboard/main/wrongQuizReview/WrongQuizReviewCard.tsx b/src/components/dashboard/main/wrongQuizReview/WrongQuizReviewCard.tsx new file mode 100644 index 0000000..21835c1 --- /dev/null +++ b/src/components/dashboard/main/wrongQuizReview/WrongQuizReviewCard.tsx @@ -0,0 +1,60 @@ +'use client'; +import Button from '@/src/components/ui/button/Button'; +import getRelativeTime from '@/src/util/time/getRelativeTime'; +import { useState } from 'react'; + +type Props = { + wrongQuiz: WrongQuiz; +}; + +export default function WrongQuizReviewCard({ wrongQuiz }: Props) { + const [mode, setMode] = useState<'question' | 'answer'>('question'); + + const toggleModeHandler = () => { + setMode((prev) => (prev === 'question' ? 'answer' : 'question')); + }; + + return ( +
+ {mode === 'question' ? ( + <> +
+

+ {wrongQuiz.video_title} +

+ +
+

+ {`Q. ${wrongQuiz.quiz_question}`} +

+ + ) : mode === 'answer' ? ( + <> +
+

+ {getRelativeTime(wrongQuiz.submitted_at)} +

+ +
+

+ {`A. ${wrongQuiz.quiz_answer}`} +

+ + ) : ( + <> + )} +
+ ); +} diff --git a/src/components/dashboard/main/wrongQuizReview/WrongQuizReviewSlider.tsx b/src/components/dashboard/main/wrongQuizReview/WrongQuizReviewSlider.tsx new file mode 100644 index 0000000..826ebb9 --- /dev/null +++ b/src/components/dashboard/main/wrongQuizReview/WrongQuizReviewSlider.tsx @@ -0,0 +1,75 @@ +'use client'; +import { useEffect, useRef, useState } from 'react'; +import { Swiper, SwiperSlide } from 'swiper/react'; +import SwiperCore from 'swiper'; +import 'swiper/css'; +import SwiperNavigationButton from '@/src/components/ui/button/SwiperNavigationButton'; +import WrongQuizReviewCard from './WrongQuizReviewCard'; + +type Props = { + wrongQuizzes: WrongQuiz[]; +}; + +export default function WrongQuizReviewSlider({ wrongQuizzes }: Props) { + const prevRef = useRef(null); + const nextRef = useRef(null); + + const [swiper, setSwiper] = useState(); + const [isFirstSlide, setIsFirstSlide] = useState(true); + const [isLastSlide, setIsLastSlide] = useState(false); + const [currPageIdx, setCurrPageIdx] = useState(1); + + const totalPage = wrongQuizzes.length; + + useEffect(() => { + if (currPageIdx === totalPage) { + setIsLastSlide(true); + } else { + setIsLastSlide(false); + } + if (currPageIdx === 1) { + setIsFirstSlide(true); + } else { + setIsFirstSlide(false); + } + }, [totalPage, currPageIdx]); + + return ( +
+ { + setSwiper(swiper); + }} + onSlideChange={(swiper) => { + setCurrPageIdx(() => swiper.activeIndex + 1); + }} + > + {wrongQuizzes.map((wrongQuiz, idx) => ( + + + + ))} + +
+ swiper?.slidePrev()} + disabled={isFirstSlide} + navigation='prev' + /> + swiper?.slideNext()} + disabled={isLastSlide} + navigation='next' + /> +
+
+ ); +} diff --git a/types/types.d.ts b/types/types.d.ts index d821597..b220ef2 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -137,6 +137,13 @@ interface LearningHistory { lecture_count: number; } +interface WrongQuiz { + quiz_question: string; + quiz_answer: string; + video_title: string; + submitted_at: string; +} + interface DashboardInfo { correctness_rate: number; completion_rate: number; @@ -144,6 +151,7 @@ interface DashboardInfo { motivation: string; latest_lectures: Course[]; learning_histories: LearningHistory[]; + wrong_quizzes: WrongQuiz[]; } interface WeekInfo { @@ -268,7 +276,8 @@ interface LectureReviewParams extends Record { interface LectureDeatilParams extends LectureIndexParams, LectureReviewParams {} interface LectureRecommendations { - recommendations: PersonalizedLecture[]; + general_recommendations: PersonalizedLecture[]; + channel_recommendations: PersonalizedLecture[]; } ///////////////////////////////////////////////////////////////////////// @@ -454,4 +463,4 @@ interface CourseReviewResponse { interface UpdateLectureReviewParams { submitted_rating: number; review_content: string; -} \ No newline at end of file +}