whooooooooooooooooooooooooooo

This commit is contained in:
2022-04-05 14:51:04 +02:00
parent 273f1e61e4
commit 840e30c550

View File

@@ -1,4 +1,4 @@
import { useState } from "react"; import { useState, useEffect } from "react";
import { import {
Pane, Pane,
TextInputField, TextInputField,
@@ -6,8 +6,8 @@ import {
Button, Button,
toaster, toaster,
Alert, Alert,
TrashIcon, TrashIcon,
Icon Icon,
} from "evergreen-ui"; } from "evergreen-ui";
import axios from "axios"; import axios from "axios";
import Footer from "./footer"; import Footer from "./footer";
@@ -17,31 +17,34 @@ export default function Manual() {
const [points, setPoints] = useState([{ id: 0, len: 0, height: 0 }]); const [points, setPoints] = useState([{ id: 0, len: 0, height: 0 }]);
const [args, setArgs] = useState({ scale: 200 }); const [args, setArgs] = useState({ scale: 200 });
//useEffect(() => {
//do something here
// }, [points]);
const reIndex=()=>{ const reIndex = () => {
let newId = 0; let newId = 0;
let newPoints = [] let newPoints = [];
for(let point of points){ for (let point of points) {
point.id = newId point.id = newId;
newPoints.push(point) newPoints.push(point);
newId += 1; newId += 1;
} }
setPoints([...newPoints]) setPoints([...newPoints]);
} };
const generation=(e)=>{ const generation = (e) => {
let pointString ="Próbkowanie: 1\nSegment 0: w dół\nX: Y, Z" let pointString = "Próbkowanie: 1\nSegment 0: w dół\nX: Y, Z";
for(let point of points){ for (let point of points) {
pointString += '\n' pointString += "\n";
pointString += Number(point.len) pointString += Number(point.len) * 1.0;
pointString += '.0, 1.0, ' pointString += ", 1.0, ";
pointString += point.height pointString += point.height;
} }
console.log(pointString) console.log(pointString);
py(e,pointString,args) py(e, pointString, args);
} };
const py = (e, profil, args) => { const py = (e, profil, args) => {
e.preventDefault(); e.preventDefault();
@@ -78,43 +81,74 @@ export default function Manual() {
placeholder="0 m" placeholder="0 m"
onChange={(e) => { onChange={(e) => {
console.log(e.target.value); console.log(e.target.value);
let newPoints = points; let newPoints = points;
newPoints[index].len = e.target.value; newPoints[index].len = e.target.value;
setPoints([...newPoints]) setPoints([...newPoints]);
}} }}
value={point.len} value={point.len}
></TextInputField> ></TextInputField>
<TextInputField <TextInputField
id={`h-${index}`} id={`h-${index}`}
placeholder="0 m n.p.m." placeholder="0 m n.p.m."
onChange={(e) => { onChange={(e) => {
console.log(e.target.value); console.log(e.target.value);
let newPoints = points; let newPoints = points;
newPoints[index].height = e.target.value; newPoints[index].height = e.target.value;
setPoints([...newPoints]) setPoints([...newPoints]);
}}
value={point.height}
onKeyDown={(e) => {
if (e.key == "Enter") {
setPoints([
...points,
{
id: points.length,
len: Number(points[points.length - 1].len) + 1,
height: 0,
},
]);
let nextDiv = e.target.parentNode.parentNode.nextSibling;
nextDiv.childNodes[1].childNodes[1].focus()
}
}} }}
value={point.height}
></TextInputField> ></TextInputField>
<Button appearance="minimal" onClick={() => { <Button
let newPoints = points; appearance="minimal"
newPoints.splice(index, 1); onClick={() => {
setPoints([...newPoints]); let newPoints = points;
reIndex(); newPoints.splice(index, 1);
}}><Icon icon={TrashIcon} color='danger'></Icon></Button> setPoints([...newPoints]);
reIndex();
}}
>
<Icon icon={TrashIcon} color="danger"></Icon>
</Button>
</Pane> </Pane>
))} ))}
</Pane> </Pane>
<Button <Button
onClick={() => { onClick={() => {
setPoints([...points, { id: points.length, len: Number(points[points.length-1].len)+1, height: 0 }]); setPoints([
...points,
{
id: points.length,
len: Number(points[points.length - 1].len) + 1,
height: 0,
},
]);
}} }}
> >
Dodaj Dodaj
</Button> </Button>
<Button appearance="primary" onClick={(e)=>{ <Button
generation(e); appearance="primary"
}}>Generuj</Button> onClick={(e) => {
generation(e);
}}
>
Generuj
</Button>
</div> </div>
</div> </div>
); );