diff --git a/components/templates/manual.js b/components/templates/manual.js index 6659050..9c7afc1 100644 --- a/components/templates/manual.js +++ b/components/templates/manual.js @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { Pane, TextInputField, @@ -6,8 +6,8 @@ import { Button, toaster, Alert, - TrashIcon, - Icon + TrashIcon, + Icon, } from "evergreen-ui"; import axios from "axios"; import Footer from "./footer"; @@ -17,31 +17,34 @@ export default function Manual() { const [points, setPoints] = useState([{ id: 0, len: 0, height: 0 }]); const [args, setArgs] = useState({ scale: 200 }); + //useEffect(() => { + //do something here + // }, [points]); - const reIndex=()=>{ - let newId = 0; - let newPoints = [] - for(let point of points){ - point.id = newId - newPoints.push(point) - newId += 1; - } - setPoints([...newPoints]) - } + const reIndex = () => { + let newId = 0; + let newPoints = []; + for (let point of points) { + point.id = newId; + newPoints.push(point); + newId += 1; + } + setPoints([...newPoints]); + }; - const generation=(e)=>{ - let pointString ="Próbkowanie: 1\nSegment 0: w dół\nX: Y, Z" + 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) - pointString += '.0, 1.0, ' - pointString += point.height + for (let point of points) { + pointString += "\n"; + pointString += Number(point.len) * 1.0; + pointString += ", 1.0, "; + pointString += point.height; } - console.log(pointString) - py(e,pointString,args) - } + console.log(pointString); + py(e, pointString, args); + }; const py = (e, profil, args) => { e.preventDefault(); @@ -78,43 +81,74 @@ export default function Manual() { placeholder="0 m" onChange={(e) => { console.log(e.target.value); - let newPoints = points; - newPoints[index].len = e.target.value; - setPoints([...newPoints]) + let newPoints = points; + newPoints[index].len = e.target.value; + setPoints([...newPoints]); }} - value={point.len} + value={point.len} > - { console.log(e.target.value); - let newPoints = points; - newPoints[index].height = e.target.value; - setPoints([...newPoints]) + let newPoints = points; + newPoints[index].height = e.target.value; + 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} > - - + ))} - + );