From 641554d8374ef229541072ddf353e0da4d1ff764 Mon Sep 17 00:00:00 2001 From: Nur Dogrusoz Date: Sat, 14 Sep 2024 12:31:29 -0400 Subject: [PATCH] Toggle assignment --- src/components/BoardSwitcher.jsx | 24 ++++++++++++++++++------ src/main.jsx | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/components/BoardSwitcher.jsx b/src/components/BoardSwitcher.jsx index e99793a..732d39d 100644 --- a/src/components/BoardSwitcher.jsx +++ b/src/components/BoardSwitcher.jsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, {useState} from "react"; function Board(props) { let className = "board"; @@ -6,20 +6,32 @@ function Board(props) { className += " selected"; } - return
{props.index + 1}
; + return
{props.index +1}
; } function BoardSwitcher(props) { + const [selectedBoardIndex, setSelectedBoardIndex] = useState(0); + + const handleClick = (event) => { + if (selectedBoardIndex === props.numBoards -1) { + selectedBoardIndex(0) + } + else{ + setSelectedBoardIndex(selectedBoardIndex + 1) + } + + } + let boards = []; - for (let ii = 0; ii < props.numBoards; ii++) { - let isSelected = ii === 0; - boards.push(); + for (let boardIndex = 0; boardIndex< props.numBoards; boardIndex++) { + let isBoardSelected = boardIndex === selectedBoardIndex; + boards.push(); } return (
{boards}
- +
); } diff --git a/src/main.jsx b/src/main.jsx index 782f402..316ad56 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -6,6 +6,6 @@ import "./index.css"; const root = ReactDOM.createRoot(document.getElementById("root")); root.render( - + );