Redesigned the Record page along with solving some bugs on the FillBlanks
This commit is contained in:
@@ -17,7 +17,9 @@ interface WordsDrawerProps {
|
||||
function WordsDrawer({words, isOpen, blankId, previouslySelectedWord, onCancel, onAnswer}: WordsDrawerProps) {
|
||||
const [selectedWord, setSelectedWord] = useState<string | undefined>(previouslySelectedWord);
|
||||
|
||||
useEffect(() => setSelectedWord(previouslySelectedWord), [previouslySelectedWord]);
|
||||
useEffect(() => {
|
||||
console.log({previouslySelectedWord}), setSelectedWord(previouslySelectedWord);
|
||||
}, [previouslySelectedWord]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -79,11 +81,11 @@ export default function FillBlanks({
|
||||
}: FillBlanksExercise & CommonProps) {
|
||||
const [answers, setAnswers] = useState<{id: string; solution: string}[]>(userSolutions);
|
||||
const [currentBlankId, setCurrentBlankId] = useState<string>();
|
||||
const [blankSelectedWord, setBlankSelectedWord] = useState<string>();
|
||||
const [isDrawerShowing, setIsDrawerShowing] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setBlankSelectedWord(currentBlankId ? answers.find((x) => x.id === currentBlankId)?.solution : undefined);
|
||||
}, [answers, currentBlankId]);
|
||||
setTimeout(() => setIsDrawerShowing(!!currentBlankId), 100);
|
||||
}, [currentBlankId]);
|
||||
|
||||
const calculateScore = () => {
|
||||
const total = text.match(/({{\d+}})/g)?.length || 0;
|
||||
@@ -120,17 +122,19 @@ export default function FillBlanks({
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col gap-4 mt-4 h-full mb-20">
|
||||
<WordsDrawer
|
||||
blankId={currentBlankId}
|
||||
words={words.map((word) => ({word, isDisabled: allowRepetition ? false : answers.map((x) => x.solution).includes(word)}))}
|
||||
previouslySelectedWord={blankSelectedWord}
|
||||
isOpen={!!currentBlankId}
|
||||
onCancel={() => setCurrentBlankId(undefined)}
|
||||
onAnswer={(solution: string) => {
|
||||
setAnswers((prev) => [...prev.filter((x) => x.id !== currentBlankId), {id: currentBlankId!, solution}]);
|
||||
setCurrentBlankId(undefined);
|
||||
}}
|
||||
/>
|
||||
{(!!currentBlankId || isDrawerShowing) && (
|
||||
<WordsDrawer
|
||||
blankId={currentBlankId}
|
||||
words={words.map((word) => ({word, isDisabled: allowRepetition ? false : answers.map((x) => x.solution).includes(word)}))}
|
||||
previouslySelectedWord={currentBlankId ? answers.find((x) => x.id === currentBlankId)?.solution : undefined}
|
||||
isOpen={isDrawerShowing}
|
||||
onCancel={() => setCurrentBlankId(undefined)}
|
||||
onAnswer={(solution: string) => {
|
||||
setAnswers((prev) => [...prev.filter((x) => x.id !== currentBlankId), {id: currentBlankId!, solution}]);
|
||||
setCurrentBlankId(undefined);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<span className="text-sm w-full leading-6">
|
||||
{prompt.split("\\n").map((line, index) => (
|
||||
<Fragment key={index}>
|
||||
|
||||
Reference in New Issue
Block a user