-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
src/components/dashboard/main/wrongQuizReview/WrongQuizReviewCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className='flex flex-col gap-2'> | ||
{mode === 'question' ? ( | ||
<> | ||
<div className='flex items-center justify-between border-b-2 border-b-sroom-white'> | ||
<p className='text-xs text-sroom-gray-100'> | ||
{wrongQuiz.video_title} | ||
</p> | ||
<Button | ||
onClick={toggleModeHandler} | ||
className='h-5 border !rounded-full w-16 bg-sroom-white text-sroom-brand | ||
mb-1' | ||
> | ||
정답보기 | ||
</Button> | ||
</div> | ||
<p className='flex items-center text-xs font-medium break-keep md:text-sm xl:text-base text-sroom-white'> | ||
{`Q. ${wrongQuiz.quiz_question}`} | ||
</p> | ||
</> | ||
) : mode === 'answer' ? ( | ||
<> | ||
<div className='flex items-center justify-between border-b-2 border-b-sroom-white'> | ||
<p className='text-xs text-sroom-gray-100'> | ||
{getRelativeTime(wrongQuiz.submitted_at)} | ||
</p> | ||
<Button | ||
onClick={toggleModeHandler} | ||
className='h-5 border !rounded-full w-16 bg-sroom-white text-sroom-brand | ||
mb-1' | ||
> | ||
문제보기 | ||
</Button> | ||
</div> | ||
<p className='flex items-center text-xs font-medium break-keep md:text-sm xl:text-base text-sroom-white'> | ||
{`A. ${wrongQuiz.quiz_answer}`} | ||
</p> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/components/dashboard/main/wrongQuizReview/WrongQuizReviewSlider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HTMLButtonElement>(null); | ||
const nextRef = useRef<HTMLButtonElement>(null); | ||
|
||
const [swiper, setSwiper] = useState<SwiperCore>(); | ||
const [isFirstSlide, setIsFirstSlide] = useState<boolean>(true); | ||
const [isLastSlide, setIsLastSlide] = useState<boolean>(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 ( | ||
<div className='flex items-center col-start-1 col-end-3 row-start-1 row-end-2 px-[5%] rounded-full bg-sroom-brand relative'> | ||
<Swiper | ||
className='!py-2 h-full' | ||
slidesPerView={1} | ||
navigation={{ | ||
prevEl: prevRef.current, | ||
nextEl: nextRef.current | ||
}} | ||
onBeforeInit={(swiper) => { | ||
setSwiper(swiper); | ||
}} | ||
onSlideChange={(swiper) => { | ||
setCurrPageIdx(() => swiper.activeIndex + 1); | ||
}} | ||
> | ||
{wrongQuizzes.map((wrongQuiz, idx) => ( | ||
<SwiperSlide key={idx} className='px-10'> | ||
<WrongQuizReviewCard wrongQuiz={wrongQuiz} /> | ||
</SwiperSlide> | ||
))} | ||
</Swiper> | ||
<div className='absolute left-0 z-20 flex items-center justify-between w-full px-5 -translate-y-1/2 top-1/2'> | ||
<SwiperNavigationButton | ||
className='rounded-full text-sroom-white' | ||
onClick={() => swiper?.slidePrev()} | ||
disabled={isFirstSlide} | ||
navigation='prev' | ||
/> | ||
<SwiperNavigationButton | ||
className='rounded-full text-sroom-white' | ||
onClick={() => swiper?.slideNext()} | ||
disabled={isLastSlide} | ||
navigation='next' | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters