diff --git a/src/components/Questions/QuestionCard.tsx b/src/components/Questions/QuestionCard.tsx new file mode 100644 index 000000000..a463bbdb5 --- /dev/null +++ b/src/components/Questions/QuestionCard.tsx @@ -0,0 +1,89 @@ +import { useEffect, useRef, useState } from 'react'; + +export function QuestionCard() { + const [isAnswerVisible, setIsAnswerVisible] = useState(false); + const answerRef = useRef(null); + const questionRef = useRef(null); + + useEffect(() => { + // set the height of the question width to the height of the answer + // width if the answer is visible and the question height is less than + // the answer height + if (isAnswerVisible) { + const answerHeight = answerRef.current?.clientHeight || 0; + const questionHeight = questionRef.current?.clientHeight || 0; + + if (answerHeight > questionHeight) { + questionRef.current!.style.height = `${answerHeight}px`; + } + + // if the user has scrolled down and the top of the answer is not + // visible, scroll to the top of the answer + const questionTop = questionRef.current?.getBoundingClientRect().top || 0; + if (questionTop < 0) { + window.scrollTo({ + top: window.scrollY + questionTop - 100, + }); + } + } else { + questionRef.current!.style.height = `auto`; + } + }, [isAnswerVisible]); + + return ( + <> +
+
+ Frontend + · + Easy Question +
+ +
+

+ What do you think is the output of the following code? +

+
+ +
+ +
+
+ +
+
+

+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam + voluptatum, quod, quas, quia, voluptates voluptate quibusdam + voluptatibus quos quae quidem. Quisqu +

+
+
+ +
+
+ + ); +} diff --git a/src/components/Questions/QuestionLoader.tsx b/src/components/Questions/QuestionLoader.tsx new file mode 100644 index 000000000..940c70237 --- /dev/null +++ b/src/components/Questions/QuestionLoader.tsx @@ -0,0 +1,9 @@ +export function QuestionLoader() { + return ( +
+

+ Please wait .. +

+
+ ); +} diff --git a/src/components/Questions/QuestionsList.tsx b/src/components/Questions/QuestionsList.tsx index f4bfed6ca..40786b916 100644 --- a/src/components/Questions/QuestionsList.tsx +++ b/src/components/Questions/QuestionsList.tsx @@ -1,12 +1,22 @@ -import { QuestionsProgress } from './QuestionsProgress'; -import { CheckCircle, SkipForward, Sparkles } from 'lucide-react'; import { useRef, useState } from 'react'; import ReactConfetti from 'react-confetti'; +import { QuestionsProgress } from './QuestionsProgress'; +import { CheckCircle, SkipForward, Sparkles } from 'lucide-react'; +import { QuestionCard } from './QuestionCard'; +import { QuestionLoader } from './QuestionLoader'; + +type ConfettiPosition = { + x: number; + y: number; + w: number; + h: number; +}; export function QuestionsList() { - const [confettiPos, setConfettiPos] = useState< - undefined | { x: number; y: number; w: number; h: number } - >(undefined); + const [isLoading, setIsLoading] = useState(false); + const [confettiPos, setConfettiPos] = useState( + undefined + ); const alreadyKnowRef = useRef(null); @@ -16,12 +26,14 @@ export function QuestionsList() { {confettiPos && ( { + onConfettiComplete={(confettiInstance) => { + confettiInstance?.reset(); setConfettiPos(undefined); }} - initialVelocityX={2} + initialVelocityX={4} initialVelocityY={8} tweenDuration={25} confettiSource={{ @@ -33,12 +45,9 @@ export function QuestionsList() { /> )} -
-
-

- Please wait .. -

-
+
+ + {isLoading && }