Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/components/BoardSwitcher.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";

function Board(props) {
let className = "board";
Expand All @@ -10,16 +10,28 @@ function Board(props) {
}

function BoardSwitcher(props) {
// State to track the currently selected board
const [selectedBoard, setSelectedBoard] = useState(0);

// Event handler for the toggle button
const handleToggle = () => {
// Update the selected board (increment by 1, loop back to 0)
setSelectedBoard((prevSelectedBoard) =>
(prevSelectedBoard + 1) % props.numBoards
);
};

let boards = [];
for (let ii = 0; ii < props.numBoards; ii++) {
let isSelected = ii === 0;
let isSelected = ii === selectedBoard;
boards.push(<Board index={ii} selected={isSelected} key={ii} />);
}

return (
<div>
<div className="boards">{boards}</div>
<button>Toggle</button>
{/* Toggle button with event handler */}
<button onClick={handleToggle}>Toggle</button>
</div>
);
}
Expand Down