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,
@@ -7,7 +7,7 @@ import {
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) => {
let pointString = "Próbkowanie: 1\nSegment 0: w dół\nX: Y, Z";
for (let point of points) {
pointString += "\n";
pointString += Number(point.len) * 1.0;
pointString += ", 1.0, ";
pointString += point.height;
} }
const generation=(e)=>{ console.log(pointString);
let pointString ="Próbkowanie: 1\nSegment 0: w dół\nX: Y, Z" py(e, pointString, args);
};
for(let point of points){
pointString += '\n'
pointString += Number(point.len)
pointString += '.0, 1.0, '
pointString += point.height
}
console.log(pointString)
py(e,pointString,args)
}
const py = (e, profil, args) => { const py = (e, profil, args) => {
e.preventDefault(); e.preventDefault();
@@ -80,7 +83,7 @@ export default function Manual() {
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>
@@ -91,30 +94,61 @@ export default function Manual() {
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} 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()
}
}}
></TextInputField> ></TextInputField>
<Button appearance="minimal" onClick={() => { <Button
appearance="minimal"
onClick={() => {
let newPoints = points; let newPoints = points;
newPoints.splice(index, 1); newPoints.splice(index, 1);
setPoints([...newPoints]); setPoints([...newPoints]);
reIndex(); reIndex();
}}><Icon icon={TrashIcon} color='danger'></Icon></Button> }}
>
<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
appearance="primary"
onClick={(e) => {
generation(e); generation(e);
}}>Generuj</Button> }}
>
Generuj
</Button>
</div> </div>
</div> </div>
); );