2022-03-24 00:28:48 -06:00
|
|
|
import React, { useCallback } from "react";
|
|
|
|
|
import { useLocalDb, useRemoteDb } from "../DbContext";
|
2022-03-12 10:32:02 -07:00
|
|
|
import "./InputPage.css";
|
2022-02-02 05:48:35 +00:00
|
|
|
import { Formik, FastField, Form } from "formik";
|
2022-01-28 13:40:10 +00:00
|
|
|
import InputNumberField from "../components/InputNumberField.jsx";
|
2022-03-13 18:58:26 -06:00
|
|
|
import { TextField, Button, Grid, FormRow, Divider, Checkbox, Radio, FormControlLabel, FormControl, FormLabel, RadioGroup, IconButton, InputAdornment, Box } from "@mui/material";
|
2022-03-24 00:28:48 -06:00
|
|
|
import { useProcessedDataBucket } from "../ProcessedDataBucketContext";
|
|
|
|
|
import { getProcessedDataBucket, updateProcessedDataBucket } from "../ProcessedDataBucket";
|
2022-01-28 13:40:10 +00:00
|
|
|
|
|
|
|
|
const InputPage = () => {
|
2022-03-24 00:28:48 -06:00
|
|
|
let { localdb, setLocaldb } = useLocalDb();
|
|
|
|
|
let { remotedb, setRemotedb } = useRemoteDb();
|
|
|
|
|
const { processedDataBucket, setProcessedDataBucket } = useProcessedDataBucket();
|
|
|
|
|
|
2022-03-13 18:58:26 -06:00
|
|
|
let panel_sx = {
|
|
|
|
|
display: "flex",
|
|
|
|
|
flexDirection: { xs: "column", sm: "row" },
|
|
|
|
|
alignItems: { xs: "center", sm: "center" },
|
|
|
|
|
justifyContent: { xs: "flex-start", sm: "center" },
|
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
|
p: 2,
|
|
|
|
|
m: 1,
|
|
|
|
|
gap: 2,
|
|
|
|
|
maxWidth: "fit-content",
|
|
|
|
|
borderRadius: "10px",
|
|
|
|
|
boxShadow: 7,
|
|
|
|
|
};
|
2022-03-24 00:28:48 -06:00
|
|
|
|
|
|
|
|
const onSubmit = useCallback(
|
|
|
|
|
(values, { setSubmitting, resetForm }) => {
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
localdb
|
|
|
|
|
.put({
|
|
|
|
|
// _id: new Date().toISOString(),
|
|
|
|
|
_id: "match_" + values.match_number + "_team_" + values.team_number,
|
2022-04-07 01:27:06 -06:00
|
|
|
_rev: new Date().toISOString(),
|
2022-04-02 17:13:50 -06:00
|
|
|
type: "match",
|
2022-03-24 00:28:48 -06:00
|
|
|
...values,
|
|
|
|
|
})
|
|
|
|
|
.then((result) => {
|
|
|
|
|
alert("Input Saved Successfully!");
|
|
|
|
|
console.log(result);
|
|
|
|
|
console.log(localdb);
|
|
|
|
|
localdb.replicate.to(remotedb, {
|
2022-04-02 17:13:50 -06:00
|
|
|
retry: true,
|
2022-03-24 00:28:48 -06:00
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
console.log("Failed To Save Input!");
|
|
|
|
|
alert(err);
|
|
|
|
|
});
|
|
|
|
|
// alert(JSON.stringify(values, null, 2));
|
2022-04-02 17:13:50 -06:00
|
|
|
resetForm(); //Hah tobad
|
2022-03-24 00:28:48 -06:00
|
|
|
setSubmitting(false);
|
|
|
|
|
// }, 400);
|
|
|
|
|
updateProcessedDataBucket(localdb, setProcessedDataBucket);
|
|
|
|
|
},
|
|
|
|
|
[localdb, remotedb, setProcessedDataBucket, updateProcessedDataBucket]
|
|
|
|
|
);
|
2022-01-28 13:40:10 +00:00
|
|
|
return (
|
2022-02-02 05:37:10 +00:00
|
|
|
<div>
|
2022-01-29 14:05:28 +00:00
|
|
|
<br />
|
2022-01-28 13:40:10 +00:00
|
|
|
<Formik
|
|
|
|
|
initialValues={{
|
|
|
|
|
team_number: "",
|
|
|
|
|
match_number: "",
|
|
|
|
|
team_abilities_well: "",
|
|
|
|
|
team_abilities_struggle: "",
|
|
|
|
|
team_abilities_cant: "",
|
|
|
|
|
fouls: "0",
|
|
|
|
|
fouls_tech: "0",
|
2022-02-02 05:37:10 +00:00
|
|
|
flipped: false,
|
2022-01-28 13:40:10 +00:00
|
|
|
red_cards: "0",
|
|
|
|
|
yellow_cards: "0",
|
|
|
|
|
disabled: false,
|
2022-02-02 05:37:10 +00:00
|
|
|
taxi_auto: false,
|
2022-01-28 13:40:10 +00:00
|
|
|
upper_hub_auto: "0",
|
|
|
|
|
lower_hub_auto: "0",
|
2022-02-02 05:37:10 +00:00
|
|
|
upper_hub_teleop: "0",
|
|
|
|
|
lower_hub_teleop: "0",
|
2022-04-02 17:13:50 -06:00
|
|
|
climb_level: "0",
|
2022-01-28 13:40:10 +00:00
|
|
|
alliance: "",
|
2022-02-02 05:37:10 +00:00
|
|
|
defence: "0",
|
2022-03-12 10:32:02 -07:00
|
|
|
disabled: false,
|
2022-01-28 13:40:10 +00:00
|
|
|
}}
|
2022-02-02 05:48:35 +00:00
|
|
|
validateOnChange="false"
|
2022-03-24 00:28:48 -06:00
|
|
|
onSubmit={onSubmit}
|
2022-03-12 10:32:02 -07:00
|
|
|
>
|
|
|
|
|
{({ values, setValues, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting }) => (
|
|
|
|
|
<Form>
|
2022-03-13 18:58:26 -06:00
|
|
|
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
|
|
|
|
|
<Box sx={panel_sx}>
|
2022-02-02 05:48:35 +00:00
|
|
|
<FastField type="input" as={TextField} name="team_number" label="Team #" />
|
|
|
|
|
<FastField type="input" as={TextField} name="match_number" label="Match Number" />
|
2022-01-28 13:40:10 +00:00
|
|
|
<FormControl component="fieldset">
|
|
|
|
|
<FormLabel component="legend">Alliance</FormLabel>
|
|
|
|
|
<RadioGroup aria-label="Alliance" name="alliance" row>
|
2022-03-13 18:58:26 -06:00
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="alliance" value="red" sx={{ "&, &.Mui-checked": { color: "red_alliance" } }} />} sx={{ color: "red_alliance" }} label="Red" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="alliance" value="blue" sx={{ "&, &.Mui-checked": { color: "blue_alliance" } }} />} sx={{ color: "blue_alliance" }} label="Blue" />
|
2022-01-28 13:40:10 +00:00
|
|
|
</RadioGroup>
|
|
|
|
|
</FormControl>
|
2022-03-13 18:58:26 -06:00
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={panel_sx}>
|
|
|
|
|
<InputNumberField name="upper_hub_auto" label="Upper Hub Auto" />
|
|
|
|
|
<InputNumberField name="lower_hub_auto" label="Lower Hub Auto" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Checkbox} type="checkbox" name="taxi_auto" />} label="Auto Taxi" />
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={panel_sx}>
|
|
|
|
|
<InputNumberField name="upper_hub_teleop" label="Upper Hub Teleop" />
|
|
|
|
|
<InputNumberField name="lower_hub_teleop" label="Lower Hub Teleop" />
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={panel_sx}>
|
2022-01-28 13:40:10 +00:00
|
|
|
<FormControl component="fieldset">
|
|
|
|
|
<FormLabel component="legend">Climbing</FormLabel>
|
|
|
|
|
<RadioGroup aria-label="Climbing" name="climb_level" row>
|
2022-03-12 10:32:02 -07:00
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="0" />} label="None" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="1" />} label="Low" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="2" />} label="Mid" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="3" />} label="High" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="climb_level" value="4" />} label="Traversal" />
|
2022-01-28 13:40:10 +00:00
|
|
|
</RadioGroup>
|
|
|
|
|
</FormControl>
|
2022-03-13 18:58:26 -06:00
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={panel_sx}>
|
|
|
|
|
<Box sx={{ display: "flex", flexDirection: "column", gap: 2 }}>
|
|
|
|
|
<InputNumberField name="fouls" label="Fouls" />
|
|
|
|
|
<InputNumberField name="fouls_tech" label="Tech Fouls" />
|
|
|
|
|
</Box>
|
|
|
|
|
<Box sx={{ display: "flex", flexDirection: "column", gap: 2 }}>
|
|
|
|
|
<InputNumberField name="red_cards" label="Red Cards" />
|
|
|
|
|
<InputNumberField name="yellow_cards" label="Yellow Cards" />
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={panel_sx}>
|
2022-01-29 14:05:28 +00:00
|
|
|
<FormControl component="fieldset">
|
|
|
|
|
<FormLabel component="legend">Defense</FormLabel>
|
|
|
|
|
<RadioGroup aria-label="Defense" name="defence" row>
|
2022-03-12 10:32:02 -07:00
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="0" />} label="None" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="1" />} label="Poor" />
|
2022-03-13 18:58:26 -06:00
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="2" />} label="Good" />
|
|
|
|
|
<FormControlLabel control={<FastField as={Radio} type="radio" name="defence" value="3" />} label="Exceptional" />
|
2022-01-29 14:05:28 +00:00
|
|
|
</RadioGroup>
|
|
|
|
|
</FormControl>
|
2022-03-12 10:32:02 -07:00
|
|
|
<FormControlLabel control={<FastField as={Checkbox} type="checkbox" name="disabled" />} label="Disabled" />
|
2022-03-13 18:58:26 -06:00
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box sx={{ ...panel_sx, display: "flex", flexDirection: "column" }}>
|
2022-04-02 17:13:50 -06:00
|
|
|
{/* <h2>What they _______</h2>
|
2022-03-13 18:58:26 -06:00
|
|
|
<Box sx={{ display: "flex", flexDirection: "row", gap: 2, p: 0, m: 0 }}>
|
|
|
|
|
<FastField type="input" as={TextField} multiline rows={3} name="team_abilities_well" label="did well" />
|
|
|
|
|
<FastField type="input" as={TextField} multiline rows={3} name="team_abilities_struggle" label="struggled with" />
|
|
|
|
|
<FastField type="input" as={TextField} multiline rows={3} name="team_abilities_cant" label="can't do" />
|
2022-04-02 17:13:50 -06:00
|
|
|
</Box> */}
|
2022-03-13 18:58:26 -06:00
|
|
|
<Button type="submit" disabled={isSubmitting}>
|
|
|
|
|
Submit
|
|
|
|
|
</Button>
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
2022-01-28 13:40:10 +00:00
|
|
|
<div />
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
|
|
|
|
</Formik>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default InputPage;
|