updated inputpage

This commit is contained in:
Aquaticholic
2022-01-29 14:05:28 +00:00
parent 87bebf8ae6
commit 001c0cb1a0
11 changed files with 263 additions and 73 deletions
+6
View File
@@ -0,0 +1,6 @@
{
"prettier.printWidth": 400,
"prettier.semi": false,
"prettier.singleQuote": true
}
+3
View File
@@ -0,0 +1,3 @@
{
"prettier.configPath": "${workspaceFolder}/.prettierrc.json"
}
Binary file not shown.
+9 -1
View File
@@ -19,7 +19,7 @@ import InputPage from "./Pages/InputPage";
import { createMuiTheme, ThemeProvider } from '@material-ui/core' import { createMuiTheme, ThemeProvider } from '@material-ui/core'
import { Formik, Field, Form } from 'formik'; import { Formik, Field, Form } from 'formik';
import { TextField, Button, Grid, FormRow, Checkbox, Radio, FormControlLabel, FormControl, FormLabel, RadioGroup, IconButton, InputAdornment } from "@material-ui/core"; import { TextField, Button, Grid, FormRow, Checkbox, Radio, FormControlLabel, FormControl, FormLabel, RadioGroup, IconButton, InputAdornment } from "@material-ui/core";
import { AddCircleOutline, RemoveCircleOutline} from "@material-ui/icons"; import { AddCircleOutline, RemoveCircleOutline } from "@material-ui/icons";
@@ -30,7 +30,15 @@ function App() {
palette: { palette: {
type: "dark", type: "dark",
}, },
typography: {
fontSize: 18
}
}); });
const styles = {
bigbution: {
}
}
return ( return (
<div className="App"> <div className="App">
<ThemeProvider theme={darkTheme}> <ThemeProvider theme={darkTheme}>
+7 -5
View File
@@ -16,7 +16,7 @@ export function DbProvider({ children }) {
const [localdb, setLocaldb] = useState(new PouchDB("testdata")); const [localdb, setLocaldb] = useState(new PouchDB("testdata"));
//used in development server //used in development server
const [remotedb, setRemotedb] = useState( const [remotedb, setRemotedb] = useState(
new PouchDB(window.location.hostname + ":5984/testdata", { new PouchDB("http://" + window.location.hostname + ":5984/testdata", {
skip_setup: true, skip_setup: true,
auth: { auth: {
username: "scouting", username: "scouting",
@@ -40,10 +40,12 @@ export function DbProvider({ children }) {
live: true, live: true,
retry: true, retry: true,
}) })
.on("change", function (change) {}) .on("change", function (change) { })
.on("paused", function (info) {}) .on("paused", function (info) { })
.on("active", function (info) {}) .on("active", function (info) { })
.on("error", function (err) {}); .on("error", function (err) {
console.error(err);
});
return ( return (
<LocalDbContext.Provider value={localdb}> <LocalDbContext.Provider value={localdb}>
@@ -0,0 +1,85 @@
import React, { useContext, useState } from "react";
import { useLocalDb } from "../../DbContext";
const ProcessedDataContext = React.createContext();
export function useProcessedData() {
return useContext(processedDataContext);
}
export function ProcessedDataProvider({ children }) {
const [processedData, setProcessedData] = useState(
{
teamData: null,
matchData: null,
updateData: function () {
const localdb = useLocalDb();
// let processed_data = {};
localdb
.allDocs({
include_docs: true,
})
.then((result) => {
console.log(result);
result.rows.forEach((dbentry) => {
let doc = dbentry.doc;
console.log(doc);
//if there's no processed data on a team yet, create a default data entry
if (typeof teamData[doc.team_name] === "undefined") {
teamData[doc.team_name] = {
team_name: doc.team_name,
alliance: doc.alliance,
games_played: 0,
climbs_none: 0,
climbs_low: 0,
climbs_mid: 0,
climbs_high: 0,
climbs_transverse: 0,
points: 0,
point_average: 0,
num_disables: 0,
disables_average: 0,
num_flips: 0,
flips_average: 0,
fouls: 0,
fouls_average: 0,
fouls_tech: 0,
fouls_tech_average: 0,
};
}
let thisTeamData = teamData[doc.team_name];
console.log(thisTeamData);
let new_team_data = {
...team_data,
games_played: team_data.games_played + 1,
num_climbs: team_data.num_climbs + (doc.climb == true ? 1 : 0),
num_disables: team_data.num_disables + (doc.disabled == true ? 1 : 0),
num_flips: team_data.num_flips + (doc.flipped_over == true ? 1 : 0),
fouls: team_data.fouls + parseInt(doc.fouls),
fouls_tech: team_data.fouls_tech + parseInt(doc.fouls_tech),
inner_port: team_data.inner_port + parseInt(doc.inner_port),
outer_port: team_data.outer_port + parseInt(doc.outer_port),
lower_port: team_data.lower_port + parseInt(doc.lower_port),
};
console.log(new_team_data);
});
})
.catch((err) => {
console.log("Error Fetching Docs from Database!");
console.log(err);
});
let datasets = [
{
data: [],
},
];
}
}
);
//https://react-charts.js.org/examples/column
return (
<ProcessedDataContext.ProcessedDataProvider value={processedData}>
{children}
</ProcessedDataContext.ProcessedDataProvider>
);
};
+13
View File
@@ -0,0 +1,13 @@
.maxwidth {
display: block;
/* margin-left: auto;
margin-right: auto; */
width: 100%;
text-align: center;
margin: auto;
max-width: fit-content;
/* max-width: 100% */
}
.smallfeild {
max-width: 25%;
}
+99 -29
View File
@@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import { useLocalDb } from "../DbContext"; import { useLocalDb } from "../DbContext";
import "./InputPage.css"
// import { Button, Intent, Spinner } from "@blueprintjs/core"; // import { Button, Intent, Spinner } from "@blueprintjs/core";
import FormRenderer from "@data-driven-forms/react-form-renderer/form-renderer"; import FormRenderer from "@data-driven-forms/react-form-renderer/form-renderer";
import componentTypes from "@data-driven-forms/react-form-renderer/component-types"; import componentTypes from "@data-driven-forms/react-form-renderer/component-types";
@@ -27,7 +28,8 @@ const InputPage = () => {
const localdb = useLocalDb(); const localdb = useLocalDb();
console.log(localdb); console.log(localdb);
return ( return (
<div> <div class="maxwidth">
<br />
<Formik <Formik
initialValues={{ initialValues={{
team_number: "", team_number: "",
@@ -47,9 +49,7 @@ const InputPage = () => {
lower_hub: "0", lower_hub: "0",
climb_level: "", climb_level: "",
alliance: "", alliance: "",
notes_good: "", defence: ""
notes_struggle: "",
notes_cant: "",
}} }}
onSubmit={(values, { setSubmitting, resetForm }) => { onSubmit={(values, { setSubmitting, resetForm }) => {
setTimeout(() => { setTimeout(() => {
@@ -61,17 +61,17 @@ const InputPage = () => {
.then((result) => { .then((result) => {
alert("Input Saved Successfully!"); alert("Input Saved Successfully!");
console.log(result); console.log(result);
console.log(localdb);
}) })
.catch((err) => { .catch((err) => {
console.log("Failed To Save Input!"); console.log("Failed To Save Input!");
alert(err); alert(err);
}); });
// alert(JSON.stringify(values, null, 2)); // alert(JSON.stringify(values, null, 2));
resetForm(); // resetForm(); //Hah tobad
setSubmitting(false); setSubmitting(false);
}, 400); }, 400);
}} }}>
>
{({ {({
values, values,
setValues, setValues,
@@ -82,14 +82,14 @@ const InputPage = () => {
handleSubmit, handleSubmit,
isSubmitting, isSubmitting,
}) => ( }) => (
<Form>
<Form >
<Grid <Grid
container container
direction="row" direction="row"
justify="center" justify="center"
alignItems="flex-start" alignItems="flex-start"
spacing={3} spacing={3}>
>
<Grid item> <Grid item>
{" "} {" "}
<Field <Field
@@ -119,9 +119,11 @@ const InputPage = () => {
type="radio" type="radio"
name="alliance" name="alliance"
value="red" value="red"
style={{ fontSize: 50 }}
/> />
} }
label="Red" label="Red"
/> />
<FormControlLabel <FormControlLabel
control={ control={
@@ -138,23 +140,21 @@ const InputPage = () => {
</FormControl> </FormControl>
</Grid> </Grid>
</Grid> </Grid>
<hr />
<div /> <div />
<Grid <Grid
container container
direction="row" direction="row"
justify="center" justify="center"
alignItems="flex-start" alignItems="flex-start"
spacing={3} spacing={3}>
>
<Grid item> <Grid item>
<Grid <Grid
container container
direction="column" direction="column"
justify="flex-start" justify="flex-start"
alignItems="center" alignItems="center"
spacing={3} spacing={3}>
>
<Grid item> <Grid item>
<InputNumberField <InputNumberField
name="upper_hub_auto" name="upper_hub_auto"
@@ -176,11 +176,10 @@ const InputPage = () => {
direction="column" direction="column"
justify="flex-start" justify="flex-start"
alignItems="center" alignItems="center"
spacing={3} spacing={3}>
>
<Grid item> <Grid item>
{" "} {" "}
<InputNumberField name="upper_hub" label="Lower Hub" />{" "} <InputNumberField name="upper_hub" label="Upper Hub" />{" "}
</Grid> </Grid>
<Grid item> <Grid item>
{" "} {" "}
@@ -189,15 +188,14 @@ const InputPage = () => {
</Grid>{" "} </Grid>{" "}
</Grid> </Grid>
</Grid> </Grid>
<hr />
<div /> <div />
<Grid <Grid
container container
direction="row" direction="row"
justify="center" justify="center"
alignItems="flex-start" alignItems="flex-start"
spacing={3} spacing={3}>
>
<Grid item> <Grid item>
<FormControl component="fieldset"> <FormControl component="fieldset">
<FormLabel component="legend">Climbing</FormLabel> <FormLabel component="legend">Climbing</FormLabel>
@@ -261,16 +259,21 @@ const InputPage = () => {
</FormControl> </FormControl>
</Grid> </Grid>
</Grid> </Grid>
<hr />
<div /> <div />
<Grid <Grid
container container
direction="row" direction="row"
justify="center" justify="center"
alignItems="flex-start" alignItems="flex-start"
spacing={3} spacing={3}>
>
<Grid item> <Grid item>
<Grid
container
direction="column"
justify="flex-start"
alignItems="center"
spacing={3}>
<Grid item> <Grid item>
<InputNumberField name="fouls" label="Fouls" />{" "} <InputNumberField name="fouls" label="Fouls" />{" "}
</Grid>{" "} </Grid>{" "}
@@ -278,7 +281,14 @@ const InputPage = () => {
<InputNumberField name="fouls_tech" label="Tech Fouls" />{" "} <InputNumberField name="fouls_tech" label="Tech Fouls" />{" "}
</Grid>{" "} </Grid>{" "}
</Grid> </Grid>
</Grid>
<Grid item> <Grid item>
<Grid
container
direction="column"
justify="flex-start"
alignItems="center"
spacing={3}>
<Grid item> <Grid item>
<InputNumberField name="red_cards" label="Red Cards" />{" "} <InputNumberField name="red_cards" label="Red Cards" />{" "}
</Grid>{" "} </Grid>{" "}
@@ -290,15 +300,76 @@ const InputPage = () => {
</Grid>{" "} </Grid>{" "}
</Grid> </Grid>
</Grid> </Grid>
<hr /> </Grid>
<div /> <div />
<Grid <Grid
container container
direction="row" direction="row"
justify="center" justify="center"
alignItems="flex-start" alignItems="flex-start"
spacing={3} spacing={3}>
> <Grid item>
<FormControl component="fieldset">
<FormLabel component="legend">Defense</FormLabel>
<RadioGroup aria-label="Defense" name="defence" row>
<FormControlLabel
control={
<Field
as={Radio}
type="radio"
name="defence"
value="0"
/>
}
label="N/A"
/>
<FormControlLabel
control={
<Field
as={Radio}
type="radio"
name="defence"
value="1"
/>
}
label="Poor"
/>
<FormControlLabel
control={
<Field
as={Radio}
type="radio"
name="defence"
value="2"
/>
}
label="Good"
/>
<FormControlLabel
control={
<Field
as={Radio}
type="radio"
name="defence"
value="3"
/>
}
label="Exceptional"
/>
</RadioGroup>
</FormControl>
</Grid>
</Grid>
<div />
<Grid
container
direction="row"
justify="center"
alignItems="flex-start"
spacing={3}>
<Grid item> <Grid item>
{" "} {" "}
<Field <Field
@@ -346,8 +417,7 @@ const InputPage = () => {
direction="row" direction="row"
justify="center" justify="center"
alignItems="flex-start" alignItems="flex-start"
spacing={3} spacing={3}>
>
<Button type="submit" disabled={isSubmitting}> <Button type="submit" disabled={isSubmitting}>
{" "} {" "}
Submit{" "} Submit{" "}
+14 -11
View File
@@ -17,7 +17,7 @@ import {
import { AddCircleOutline, RemoveCircleOutline } from "@material-ui/icons"; import { AddCircleOutline, RemoveCircleOutline } from "@material-ui/icons";
const InputNumberField = (props) => { const InputNumberField = (props) => {
const { values, setValues } = useFormikContext(); const { values, setFieldValue } = useFormikContext();
return ( return (
<Field <Field
type="number" type="number"
@@ -25,17 +25,18 @@ const InputNumberField = (props) => {
name={props.name} name={props.name}
label={props.label} label={props.label}
InputProps={{ InputProps={{
style: { fontSize: 40, "max-width": 300 },
startAdornment: ( startAdornment: (
<InputAdornment position="start"> <InputAdornment position="start">
<IconButton <IconButton
onClick={() => { onClick={() => {
setValues({ setFieldValue(props.name, Math.max(parseInt(values[props.name]) - 1, 0));
...values,
[props.name]: Math.max(parseInt(values[props.name]) - 1, 0),
});
}} }}
iconStyle={{ width: '48px', height: '48px' }}
style={{ width: '96px', height: '96px', padding: '24px' }}
touch={true}
> >
<RemoveCircleOutline /> <RemoveCircleOutline style={{ fontSize: 50 }} />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
), ),
@@ -43,13 +44,15 @@ const InputNumberField = (props) => {
<InputAdornment position="end"> <InputAdornment position="end">
<IconButton <IconButton
onClick={() => { onClick={() => {
setValues({ setFieldValue(props.name, Math.max(parseInt(values[props.name]) + 1, 0));
...values,
[props.name]: parseInt(values[props.name]) + 1,
});
}} }}
iconStyle={{ width: '100px', height: '100px' }}
style={{ width: '96px', height: '96px', padding: '0' }}
touch={true}
size="large"
> >
<AddCircleOutline /> <AddCircleOutline style={{ fontSize: 50 }} />
</IconButton> </IconButton>
</InputAdornment> </InputAdornment>
), ),