Skip to content

Commit

Permalink
work on starting positoin buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
liujip0 committed Feb 16, 2025
1 parent 1fb63c1 commit 35eca0e
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 134 deletions.
54 changes: 54 additions & 0 deletions app/src/scout/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,60 @@ export function CircleToggle({
);
}

type TransparentToggleProps = {
value: boolean;
setValue: (value: boolean) => void;
label: string;
disabled?: boolean;
error: boolean;
sx: {
width?: string;
height?: string;
transform?: string;
top?: string;
left?: string;
right?: string;
bottom?: string;
};
};
export function TransparentToggle({
value,
setValue,
label,
disabled,
error,
sx,
}: TransparentToggleProps) {
return (
<ToggleButton
value="toggle"
selected={value}
onChange={() => {
setValue(!value);
}}
disabled={disabled}
sx={(theme) => ({
...sx,
position: "absolute",
color: theme.palette.secondary.main,
backgroundColor: theme.palette.primary.main + "40",
borderColor:
!error ? theme.palette.secondary.main : theme.palette.error.main,
"&:hover": {
backgroundColor: theme.palette.primary.main + "40",
},
padding: 1,
borderWidth: 2,
"&.Mui-selected, &.Mui-selected:hover": {
color: theme.palette.primary.main,
backgroundColor: theme.palette.secondary.main,
},
})}>
{label}
</ToggleButton>
);
}

type CircleButtonProps = {
label: string;
onClick: React.MouseEventHandler<HTMLButtonElement>;
Expand Down
166 changes: 66 additions & 100 deletions app/src/scout/ScoutLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,69 @@ export default function ScoutLayout({
const [scoutNameError, setScoutNameError] = useState("");
const [scoutTeamNumberError, setScoutTeamNumberError] = useState("");
const [teamNumberError, setTeamNumberError] = useState("");
const [startingPositionError, setStartingPositionError] = useState("");

const prematchCheck = () => {
let error = false;

if (
!events
.find((x) => x.eventKey === deviceSetup.currentEvent)
?.matches.some((y) => y.matchKey === match.matchKey)
) {
if (
matchNumberError !== "Invalid match key. Press Next again to ignore."
) {
error = true;
}
setMatchNumberError("Invalid match key. Press Next again to ignore.");
} else {
setMatchNumberError("");
}

if (!match.scoutName) {
error = true;
setScoutNameError("Cannot be empty.");
} else {
setScoutNameError("");
}

if (
!match.scoutTeamNumber ||
match.scoutTeamNumber < 0 ||
match.scoutTeamNumber > MAX_TEAM_NUMBER
) {
error = true;
setScoutTeamNumberError("Invalid team number.");
} else {
setScoutTeamNumberError("");
}

if (
!match.teamNumber ||
match.teamNumber < 0 ||
match.teamNumber > MAX_TEAM_NUMBER
) {
error = true;
setTeamNumberError("Invalid team number.");
} else {
setTeamNumberError("");
}

if (
!(match as TeamMatchEntry).noShow &&
!(match as TeamMatchEntry).startingLocationA &&
!(match as TeamMatchEntry).startingLocationB &&
!(match as TeamMatchEntry).startingLocationC
) {
error = true;
setStartingPositionError("Starting position must be selected.");
} else {
setStartingPositionError("");
}

return error;
};

return (
<ScoutPageContainer
Expand All @@ -103,56 +166,7 @@ export default function ScoutLayout({
value={matchStage}
onChange={(_event, value) => {
if (matchStage === "prematch") {
let error = false;

if (
!events
.find((x) => x.eventKey === deviceSetup.currentEvent)
?.matches.some((y) => y.matchKey === match.matchKey)
) {
if (
matchNumberError !==
"Invalid match key. Press Next again to ignore."
) {
error = true;
}
setMatchNumberError(
"Invalid match key. Press Next again to ignore."
);
} else {
setMatchNumberError("");
}

if (!match.scoutName) {
error = true;
setScoutNameError("Cannot be empty.");
} else {
setScoutNameError("");
}

if (
!match.scoutTeamNumber ||
match.scoutTeamNumber < 0 ||
match.scoutTeamNumber > MAX_TEAM_NUMBER
) {
error = true;
setScoutTeamNumberError("Invalid team number.");
} else {
setScoutTeamNumberError("");
}

if (
!match.teamNumber ||
match.teamNumber < 0 ||
match.teamNumber > MAX_TEAM_NUMBER
) {
error = true;
setTeamNumberError("Invalid team number.");
} else {
setTeamNumberError("");
}

if (!error) {
if (!prematchCheck) {
setMatchStage(value);
}
} else {
Expand Down Expand Up @@ -215,56 +229,7 @@ export default function ScoutLayout({
onClick={() => {
switch (matchStage) {
case "prematch": {
let error = false;

if (
!events
.find((x) => x.eventKey === deviceSetup.currentEvent)
?.matches.some((y) => y.matchKey === match.matchKey)
) {
if (
matchNumberError !==
"Invalid match key. Press Continue again to ignore."
) {
error = true;
}
setMatchNumberError(
"Invalid match key. Press Continue again to ignore."
);
} else {
setMatchNumberError("");
}

if (!match.scoutName) {
error = true;
setScoutNameError("Cannot be empty.");
} else {
setScoutNameError("");
}

if (
!match.scoutTeamNumber ||
match.scoutTeamNumber < 0 ||
match.scoutTeamNumber > MAX_TEAM_NUMBER
) {
error = true;
setScoutTeamNumberError("Invalid team number.");
} else {
setScoutTeamNumberError("");
}

if (
!match.teamNumber ||
match.teamNumber < 0 ||
match.teamNumber > MAX_TEAM_NUMBER
) {
error = true;
setTeamNumberError("Invalid team number.");
} else {
setTeamNumberError("");
}

if (!error) {
if (!prematchCheck()) {
if ((match as TeamMatchEntry).noShow) {
putEntries.mutate([
{
Expand Down Expand Up @@ -388,6 +353,7 @@ export default function ScoutLayout({
scoutNameError={scoutNameError}
scoutTeamNumberError={scoutTeamNumberError}
teamNumberError={teamNumberError}
startingPositionError={startingPositionError}
/>
),
auto: (
Expand Down
41 changes: 22 additions & 19 deletions app/src/scout/robot/Prematch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Add, Remove } from "@mui/icons-material";
import { Box, Divider, IconButton, Stack, TextField } from "@mui/material";
import { StyledRedToggleButton } from "../../components/StyledToggleButton.tsx";
import { DeviceSetupObj } from "../../setup/DeviceSetup.tsx";
import { CircleToggle } from "../Components.tsx";
import { TransparentToggle } from "../Components.tsx";
import BlueBarge from "../images/BlueBarge.png";
import BlueProcessor from "../images/BlueProcessor.png";
import RedBarge from "../images/RedBarge.png";
Expand All @@ -22,6 +22,7 @@ type PrematchProps = {
scoutNameError: string;
scoutTeamNumberError: string;
teamNumberError: string;
startingPositionError: string;
};
export default function Prematch({
match,
Expand All @@ -32,6 +33,7 @@ export default function Prematch({
scoutNameError,
scoutTeamNumberError,
teamNumberError,
startingPositionError,
}: PrematchProps) {
return (
<Stack
Expand Down Expand Up @@ -265,7 +267,8 @@ export default function Prematch({
height: "100%",
}}
/>
<CircleToggle
<Box></Box>
<TransparentToggle
label="A"
value={match.startingLocationA!}
setValue={(value) => {
Expand All @@ -284,23 +287,23 @@ export default function Prematch({
}
}}
disabled={match.noShow}
error={startingPositionError !== ""}
sx={
deviceSetup.fieldOrientation === "barge" ?
{
position: "absolute",
left: "14%",
top: "25%",
transform: "translate(-50%, -50%)",
left: "8%",
top: "13%",
width: "20%",
height: "27%",
}
: {
position: "absolute",
right: "14%",
bottom: "25%",
transform: "translate(50%, 50%)",
}
}
/>
<CircleToggle
<TransparentToggle
label="B"
value={match.startingLocationB!}
setValue={(value) => {
Expand All @@ -319,23 +322,23 @@ export default function Prematch({
}
}}
disabled={match.noShow}
error={startingPositionError !== ""}
sx={
deviceSetup.fieldOrientation === "barge" ?
{
position: "absolute",
left: "14%",
top: "53%",
transform: "translate(-50%, -50%)",
left: "8%",
top: "40%",
width: "20%",
height: "27%",
}
: {
position: "absolute",
right: "14%",
bottom: "53%",
transform: "translate(50%, 50%)",
}
}
/>
<CircleToggle
<TransparentToggle
label="C"
value={match.startingLocationC!}
setValue={(value) => {
Expand All @@ -354,16 +357,16 @@ export default function Prematch({
}
}}
disabled={match.noShow}
error={startingPositionError !== ""}
sx={
deviceSetup.fieldOrientation === "barge" ?
{
position: "absolute",
left: "14%",
bottom: "18%",
transform: "translate(-50%, 50%)",
left: "8%",
top: "67%",
width: "20%",
height: "27%",
}
: {
position: "absolute",
right: "14%",
top: "18%",
transform: "translate(50%, -50%)",
Expand Down
Loading

0 comments on commit 35eca0e

Please sign in to comment.