Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BoardSwitcher.jsx #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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