process bar

main
alex 2024-08-10 20:50:28 +02:00
parent c1582768ec
commit 413425adca
1 changed files with 44 additions and 17 deletions

View File

@ -73,8 +73,15 @@ function App() {
.then((response) => { .then((response) => {
console.log(response); console.log(response);
setRemainingTimeProgress(response.runningUntil); if (response.acceleration !== undefined)
setProcessStatus(response.status); setAcceleration(response.acceleration);
if (response.duration !== undefined)
form.setFieldValue("duration", response.duration === true ? 1 : 0);
if (response.distance !== undefined) setDistance(response.distance);
if (response.direction !== undefined) setDirection(response.direction);
if (response.runningUntil !== undefined)
setRemainingTimeProgress(response.runningUntil);
if (response.status !== undefined) setProcessStatus(response.status);
}) })
.catch((error) => { .catch((error) => {
console.error(error); console.error(error);
@ -90,16 +97,17 @@ function App() {
} }
setRemainingTime((prev) => { setRemainingTime((prev) => {
const newTime = prev - 1000; const newTime = prev - 150;
if (newTime <= 0) { if (newTime <= 0) {
remainingTimeRef.current = 0;
clearInterval(intervalRef.current); clearInterval(intervalRef.current);
setRemainingTimeProgress(0);
setProcessStatus("Fertig");
} }
return newTime; return newTime;
}); });
}, 1000); }, 150);
return () => { return () => {
clearInterval(intervalRef.current); clearInterval(intervalRef.current);
@ -107,6 +115,8 @@ function App() {
}, [remainingTimeRef.current]); }, [remainingTimeRef.current]);
const sendControlRequest = (urlPath) => { const sendControlRequest = (urlPath) => {
setRemainingTimeProgress(0);
form form
.validateFields() .validateFields()
.then((values) => { .then((values) => {
@ -165,18 +175,35 @@ function App() {
<Form.Item <Form.Item
label={`Status${procesStatus !== "" ? `: ${procesStatus}` : ""}`} label={`Status${procesStatus !== "" ? `: ${procesStatus}` : ""}`}
> >
<Progress <Space style={{ display: "block" }}>
percent={ <Progress
100 - percent={
Math.round((remainingTime / remainingTimeRef.current) * 100) procesStatus === "Fertig"
} ? 100
type="line" : 100 -
status="active" (
strokeColor={{ (100 / remainingTimeRef.current) *
from: "#108ee9", remainingTime
to: "#87d068", ).toFixed(2)
}} }
/> showInfo={false}
type="line"
status="active"
strokeColor={{
from: "#108ee9",
to: "#87d068",
}}
/>
<span
style={{
display: "inline-block",
width: 100,
textAlign: "right",
}}
>
{(remainingTime / 1000).toFixed(1)} Sekunden
</span>
</Space>
</Form.Item> </Form.Item>
<Divider /> <Divider />