From 85edf2e16d7e6fe7473c5291dc130e1a54fd6cf2 Mon Sep 17 00:00:00 2001 From: Kanstantinas Piatrashka Date: Sun, 17 Dec 2023 18:51:04 +0200 Subject: [PATCH] attempt to make flashcard game more obvious --- .../src/components/FlashcardShufflePlay.tsx | 65 ++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) 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);