mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
adds spinner to async task when waiting for backend status update
This commit is contained in:
parent
503240aeae
commit
a73e721b73
@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { runMethod } from '../socket';
|
import { runMethod } from '../socket';
|
||||||
import { Form, Button, InputGroup } from 'react-bootstrap';
|
import { Form, Button, InputGroup, Spinner } from 'react-bootstrap';
|
||||||
import { DocStringComponent } from './DocStringComponent';
|
import { DocStringComponent } from './DocStringComponent';
|
||||||
import { LevelName } from './NotificationsComponent';
|
import { LevelName } from './NotificationsComponent';
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
|||||||
|
|
||||||
const renderCount = useRef(0);
|
const renderCount = useRef(0);
|
||||||
const formRef = useRef(null);
|
const formRef = useRef(null);
|
||||||
|
const [spinning, setSpinning] = useState(false);
|
||||||
const name = fullAccessPath.split('.').at(-1);
|
const name = fullAccessPath.split('.').at(-1);
|
||||||
const parentPath = fullAccessPath.slice(0, -(name.length + 1));
|
const parentPath = fullAccessPath.slice(0, -(name.length + 1));
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
|||||||
message = `${fullAccessPath} was started.`;
|
message = `${fullAccessPath} was started.`;
|
||||||
}
|
}
|
||||||
addNotification(message);
|
addNotification(message);
|
||||||
|
setSpinning(false);
|
||||||
}, [props.value]);
|
}, [props.value]);
|
||||||
|
|
||||||
const execute = async (event: React.FormEvent) => {
|
const execute = async (event: React.FormEvent) => {
|
||||||
@ -58,6 +60,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const accessPath = [parentPath, method_name].filter((element) => element).join('.');
|
const accessPath = [parentPath, method_name].filter((element) => element).join('.');
|
||||||
|
setSpinning(true);
|
||||||
runMethod(accessPath);
|
runMethod(accessPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,7 +76,13 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
|||||||
<DocStringComponent docString={docString} />
|
<DocStringComponent docString={docString} />
|
||||||
</InputGroup.Text>
|
</InputGroup.Text>
|
||||||
<Button id={`button-${id}`} type="submit">
|
<Button id={`button-${id}`} type="submit">
|
||||||
{runningTask === 'RUNNING' ? 'Stop ' : 'Start '}
|
{spinning ? (
|
||||||
|
<Spinner size="sm" role="status" aria-hidden="true" />
|
||||||
|
) : runningTask === 'RUNNING' ? (
|
||||||
|
'Stop '
|
||||||
|
) : (
|
||||||
|
'Start '
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
</Form>
|
</Form>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user