mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 08:20:02 +02:00
feat: adding "emit_update" function
This commit is contained in:
parent
c5bbaad58d
commit
80fe1051f1
@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { socket } from '../socket';
|
||||
import { emit_update } from '../socket';
|
||||
import { InputGroup, Form, Button } from 'react-bootstrap';
|
||||
import { DocStringComponent } from './DocStringComponent';
|
||||
|
||||
@ -31,11 +31,7 @@ export const AsyncMethodComponent = React.memo((props: AsyncMethodProps) => {
|
||||
method_name = `start_${name}`;
|
||||
}
|
||||
|
||||
socket.emit('frontend_update', {
|
||||
name: method_name,
|
||||
parent_path: parent_path,
|
||||
value: { args: args }
|
||||
});
|
||||
emit_update(method_name, parent_path, { args: args });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { ToggleButton } from 'react-bootstrap';
|
||||
import { socket } from '../socket';
|
||||
import { emit_update } from '../socket';
|
||||
import { DocStringComponent } from './DocStringComponent';
|
||||
|
||||
interface ButtonComponentProps {
|
||||
@ -23,11 +23,7 @@ export const ButtonComponent = React.memo((props: ButtonComponentProps) => {
|
||||
const buttonName = mapping ? (value ? mapping[0] : mapping[1]) : name;
|
||||
|
||||
const setChecked = (checked: boolean) => {
|
||||
socket.emit('frontend_update', {
|
||||
name: name,
|
||||
parent_path: parent_path,
|
||||
value: checked
|
||||
});
|
||||
emit_update(name, parent_path, checked);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { InputGroup, Form, Row, Col } from 'react-bootstrap';
|
||||
import { socket } from '../socket';
|
||||
import { emit_update } from '../socket';
|
||||
import { DocStringComponent } from './DocStringComponent';
|
||||
|
||||
interface EnumComponentProps {
|
||||
@ -21,11 +21,7 @@ export const EnumComponent = React.memo((props: EnumComponentProps) => {
|
||||
const { name, parent_path, value, docString, enumDict } = props;
|
||||
|
||||
const handleValueChange = (newValue: string) => {
|
||||
socket.emit('frontend_update', {
|
||||
name: name,
|
||||
parent_path: parent_path,
|
||||
value: newValue
|
||||
});
|
||||
emit_update(name, parent_path, newValue);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { socket } from '../socket';
|
||||
import { emit_update } from '../socket';
|
||||
import { Button, InputGroup, Form, Collapse } from 'react-bootstrap';
|
||||
import { DocStringComponent } from './DocStringComponent';
|
||||
|
||||
@ -27,20 +27,12 @@ export const MethodComponent = React.memo((props: MethodProps) => {
|
||||
Object.keys(props.parameters).forEach(
|
||||
(name) => (args[name] = event.target[name].value)
|
||||
);
|
||||
socket.emit(
|
||||
'frontend_update',
|
||||
{
|
||||
name: name,
|
||||
parent_path: parent_path,
|
||||
value: { args: args }
|
||||
},
|
||||
(ack) => {
|
||||
// Update the functionCalls state with the new call if we get an acknowledge msg
|
||||
if (ack !== undefined) {
|
||||
setFunctionCalls((prevCalls) => [...prevCalls, { name, args, result: ack }]);
|
||||
}
|
||||
emit_update(name, parent_path, { args: args }, (ack) => {
|
||||
// Update the functionCalls state with the new call if we get an acknowledge msg
|
||||
if (ack !== undefined) {
|
||||
setFunctionCalls((prevCalls) => [...prevCalls, { name, args, result: ack }]);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { InputGroup, Form, Row, Col, Button, Collapse } from 'react-bootstrap';
|
||||
import { socket } from '../socket';
|
||||
import { emit_update } from '../socket';
|
||||
import { DocStringComponent } from './DocStringComponent';
|
||||
import { Slider } from '@mui/material';
|
||||
|
||||
@ -31,10 +31,11 @@ export const SliderComponent = React.memo((props: SliderComponentProps) => {
|
||||
max: number = props.max,
|
||||
stepSize: number = props.stepSize
|
||||
) => {
|
||||
socket.emit('frontend_update', {
|
||||
name: name,
|
||||
parent_path: parent_path,
|
||||
value: { value: newNumber, min: min, max: max, step_size: stepSize }
|
||||
emit_update(name, parent_path, {
|
||||
value: newNumber,
|
||||
min: min,
|
||||
max: max,
|
||||
step_size: stepSize
|
||||
});
|
||||
};
|
||||
const handleOnChange = (event, newNumber: number | number[]) => {
|
||||
|
@ -8,3 +8,12 @@ const URL = `ws://${hostname}:${port}/`;
|
||||
console.debug('Websocket: ', URL);
|
||||
|
||||
export const socket = io(URL, { path: '/ws/socket.io', transports: ['websocket'] });
|
||||
|
||||
export const emit_update = (
|
||||
name: string,
|
||||
parent_path: string,
|
||||
value: unknown,
|
||||
callback?: (ack: unknown) => void
|
||||
) => {
|
||||
socket.emit('frontend_update', { name, parent_path, value }, callback);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user