From 5720b524ba3960e3687a65add21ffbf75c5be44a Mon Sep 17 00:00:00 2001 From: Daniel Kao Date: Sun, 25 Feb 2024 21:39:15 -0800 Subject: [PATCH] make hint box highlight, disable address buttons on correct, and fix ex 3 --- src/components/Grid.tsx | 4 ++++ src/components/HintBox.tsx | 17 ++++++++--------- src/components/ShelfAddress.tsx | 15 ++++++++++++--- src/pages/Demo.tsx | 9 +++++---- src/pages/Exercise3.tsx | 4 +++- src/pages/Exercise4.tsx | 2 +- src/styles/HintBox.scss | 2 +- src/styles/ShelfAddress.scss | 2 +- 8 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/components/Grid.tsx b/src/components/Grid.tsx index 933d2afe..7bad956a 100644 --- a/src/components/Grid.tsx +++ b/src/components/Grid.tsx @@ -6,6 +6,8 @@ export interface GridProps { size: number; addressNums: number[]; itemSpaceArray: number[]; + correctAddress?: number; + disabled: boolean; handleCorrect: Dispatch>; handleIncorrect: Dispatch>; style?: CSSProperties; @@ -31,6 +33,8 @@ export default function Grid(props: GridProps): JSX.Element { diff --git a/src/components/HintBox.tsx b/src/components/HintBox.tsx index 04129e26..25a5e157 100644 --- a/src/components/HintBox.tsx +++ b/src/components/HintBox.tsx @@ -9,20 +9,13 @@ interface HintBoxProps { function HintBox(props: HintBoxProps): JSX.Element { const [expanded, setExpanded] = useState(false); - const [selectionMade] = useState(false); const handleToggle = () => { - if (!props.noClose || !expanded) { + if (props.noClose && !expanded) { setExpanded(!expanded); } }; - useEffect(() => { - if (selectionMade) { - setExpanded(true); - } - }, [selectionMade]); - useEffect(() => { setExpanded(props.correct || false); }, [props.correct]); @@ -30,7 +23,13 @@ function HintBox(props: HintBoxProps): JSX.Element { return (
diff --git a/src/components/ShelfAddress.tsx b/src/components/ShelfAddress.tsx index 00904345..9b3033d9 100644 --- a/src/components/ShelfAddress.tsx +++ b/src/components/ShelfAddress.tsx @@ -3,24 +3,33 @@ import '../styles/ShelfAddress.scss'; interface ShelfAddressProps { num: number; + correctAddress: boolean; + disabled: boolean; handleCorrect: Dispatch>; handleIncorrect: Dispatch>; } export default function ShelfAddress(props: ShelfAddressProps): JSX.Element { const [color, setColor] = useState('#C4C4C4'); + const [hover, setHover] = useState(false); const handleClick = async () => { if (color != '#C4C4C4') return; - if (props.num == 42) { + if (props.correctAddress) { props.handleCorrect(true); - setColor('green'); + setColor('#31A74B'); } else { props.handleIncorrect(true); setColor('red'); } }; return ( -