diff --git a/better-frontend/src/components/FlashcardShufflePlay.tsx b/better-frontend/src/components/FlashcardShufflePlay.tsx index d0b50c39..f85960b0 100644 --- a/better-frontend/src/components/FlashcardShufflePlay.tsx +++ b/better-frontend/src/components/FlashcardShufflePlay.tsx @@ -1,6 +1,13 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { FlashcardDto } from "../types/flashcard"; -import { Button, HStack, Heading, Text, VStack } from "@chakra-ui/react"; +import { + Button, + HStack, + Heading, + Progress, + Text, + VStack, +} from "@chakra-ui/react"; function shuffle(arr: T[]): T[] { return Array.from(arr).sort(() => Math.random() - 0.5); @@ -15,16 +22,19 @@ export default function FlashcardShufflePlay({ const [nextLeftFlashcards, setNextLeftFlashcards] = useState( [] ); + const [rememberedFlashcards, setRememberedFlashcards] = useState< + FlashcardDto[] + >([]); - useEffect(() => { - if (leftFlashcards.length === 0 && nextLeftFlashcards.length > 0) { - setLeftFlashcards(shuffle(nextLeftFlashcards)); - setNextLeftFlashcards([]); - } - }, [leftFlashcards, nextLeftFlashcards]); + function nextRound() { + setLeftFlashcards(shuffle(nextLeftFlashcards)); + setNextLeftFlashcards([]); + setRememberedFlashcards([]); + } function remember() { setLeftFlashcards(leftFlashcards.filter((_v, i) => i !== 0)); + setRememberedFlashcards([...rememberedFlashcards, leftFlashcards[0]]); } function repeat() { @@ -43,9 +53,28 @@ export default function FlashcardShufflePlay({ ); } + if (leftFlashcards.length === 0 && nextLeftFlashcards.length > 0) { + return ( + + ); + } + if (leftFlashcards.length > 0) { return ( <> + @@ -56,6 +85,26 @@ export default function FlashcardShufflePlay({ } } +function NextRoundView({ + rememberedCount, + nextCount, + onProceed, +}: { + rememberedCount: number; + nextCount: number; + onProceed: () => void; +}) { + return ( + + Your progress so far + + {rememberedCount} remembered, {nextCount} left + + + + ); +} + function Flashcard({ flashcard }: { flashcard: FlashcardDto }) { const [isFlipped, setIsFlipped] = useState(false);