Update question ui

pull/4446/head
Kamran Ahmed 1 year ago
parent 1eb0e8869a
commit 5bbcd85e6c
  1. 4
      src/components/Questions/QuestionCard.tsx
  2. 8
      src/components/Questions/QuestionsList.tsx
  3. 39
      src/components/Questions/QuestionsProgress.tsx

@ -22,10 +22,10 @@ export function QuestionCard() {
// if the user has scrolled down and the top of the answer is not // if the user has scrolled down and the top of the answer is not
// visible, scroll to the top of the answer // visible, scroll to the top of the answer
const questionTop = questionRef.current?.getBoundingClientRect().top || 0; const questionTop = (questionRef.current?.getBoundingClientRect().top || 0) - 147;
if (questionTop < 0) { if (questionTop < 0) {
window.scrollTo({ window.scrollTo({
top: window.scrollY + questionTop - 100, top: window.scrollY + questionTop - 10,
}); });
} }
}, [isAnswerVisible]); }, [isAnswerVisible]);

@ -4,6 +4,7 @@ import { QuestionsProgress } from './QuestionsProgress';
import { CheckCircle, SkipForward, Sparkles } from 'lucide-react'; import { CheckCircle, SkipForward, Sparkles } from 'lucide-react';
import { QuestionCard } from './QuestionCard'; import { QuestionCard } from './QuestionCard';
import { QuestionLoader } from './QuestionLoader'; import { QuestionLoader } from './QuestionLoader';
import { isLoggedIn } from '../../lib/jwt';
type ConfettiPosition = { type ConfettiPosition = {
x: number; x: number;
@ -14,6 +15,7 @@ type ConfettiPosition = {
export function QuestionsList() { export function QuestionsList() {
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
const [givenAnswers, setGivenAnswers] = useState<string[]>([]);
const [confettiPos, setConfettiPos] = useState<undefined | ConfettiPosition>( const [confettiPos, setConfettiPos] = useState<undefined | ConfettiPosition>(
undefined undefined
); );
@ -22,7 +24,9 @@ export function QuestionsList() {
return ( return (
<div className="mb-40 gap-3 text-center"> <div className="mb-40 gap-3 text-center">
<QuestionsProgress /> <QuestionsProgress
showLoginAlert={!isLoggedIn() && givenAnswers.length !== 0}
/>
{confettiPos && ( {confettiPos && (
<ReactConfetti <ReactConfetti
@ -66,6 +70,8 @@ export function QuestionsList() {
w: alreadyKnowRect?.width || 0, w: alreadyKnowRect?.width || 0,
h: alreadyKnowRect?.height || 0, h: alreadyKnowRect?.height || 0,
}); });
setGivenAnswers((prev) => [...prev, 'alreadyKnow']);
}} }}
className="flex flex-1 items-center rounded-xl border border-gray-300 bg-white py-3 px-4 text-black transition-colors hover:border-black hover:bg-black hover:text-white" className="flex flex-1 items-center rounded-xl border border-gray-300 bg-white py-3 px-4 text-black transition-colors hover:border-black hover:bg-black hover:text-white"
> >

@ -1,15 +1,15 @@
import { import { CheckCircle, RotateCcw, Sparkles } from 'lucide-react';
Check, import { showLoginPopup } from '../../lib/popup';
CheckCircle,
Lightbulb, type QuestionsProgressProps = {
PartyPopper, showLoginAlert?: boolean;
RotateCcw, };
Sparkles,
} from 'lucide-react'; export function QuestionsProgress(props: QuestionsProgressProps) {
const { showLoginAlert } = props;
export function QuestionsProgress() {
return ( return (
<div className="mb-5 rounded-lg border border-gray-300 bg-white p-6 overflow-hidden"> <div className="mb-5 overflow-hidden rounded-lg border border-gray-300 bg-white p-6">
<div className="mb-3 flex items-center text-gray-600"> <div className="mb-3 flex items-center text-gray-600">
<div className="relative w-full flex-1 rounded-xl bg-gray-200 p-1"> <div className="relative w-full flex-1 rounded-xl bg-gray-200 p-1">
<div className="absolute bottom-0 left-0 top-0 w-[30%] rounded-xl bg-slate-800"></div> <div className="absolute bottom-0 left-0 top-0 w-[30%] rounded-xl bg-slate-800"></div>
@ -40,12 +40,19 @@ export function QuestionsProgress() {
</button> </button>
</div> </div>
<p className="-mx-6 mt-6 -mb-6 border-t bg-yellow-100 py-3 text-sm text-yellow-900"> {showLoginAlert && (
You progress will not be saved. Please{' '} <p className="-mx-6 mt-6 -mb-6 border-t bg-yellow-100 py-3 text-sm text-yellow-900">
<button className="underline-offset-3 font-medium underline"> You progress is not saved. Please{' '}
login to save your progress. <button
</button> onClick={() => {
</p> showLoginPopup();
}}
className="underline-offset-3 font-medium underline hover:text-black"
>
login to save your progress.
</button>
</p>
)}
</div> </div>
); );
} }

Loading…
Cancel
Save