diff --git a/src/components/molecules/AddWhatCondModal.tsx b/src/components/molecules/AddWhatCondModal.tsx index 5fadfaa6..ac49aa02 100644 --- a/src/components/molecules/AddWhatCondModal.tsx +++ b/src/components/molecules/AddWhatCondModal.tsx @@ -15,17 +15,17 @@ interface AddWhatCondModalProps { index: number; } -export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModalProps) => { +export const AddWhatCondModal = ({ isOpen, onClose, pair, index }: AddWhatCondModalProps) => { const [action, setAction] = React.useState(''); const [objectIndex, setObjectIndex] = React.useState(0); - const [args, setArgs] = React.useState<({type: string, value: (string|number|object|unknown)})[]>([]); + const [args, setArgs] = React.useState<({ type: string, value: (string | number | object | unknown) })[]>([]); - const objectRefs = useRef<({getObject: () => object}|unknown)[]>([]); + const objectRefs = useRef<({ getObject: () => object } | unknown)[]>([]); - const {socket} = useSocketStore(); + const { socket } = useSocketStore(); const handleSubmit = () => { - const argsArray: (string|number|object|unknown)[] = []; + const argsArray: (string | number | object | unknown)[] = []; args.map((arg, index) => { switch (arg.type) { case 'string': @@ -44,7 +44,7 @@ export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModa action, args: argsArray, }) - socket?.emit('updatePair', {index: index-1, pair: pair}); + socket?.emit('updatePair', { index: index - 1, pair: pair }); } return ( @@ -53,8 +53,8 @@ export const AddWhatCondModal = ({isOpen, onClose, pair, index}: AddWhatCondModa onClose(); }} modalStyle={modalStyle}>
- Add what condition: -
+ Add what condition: +
Action:
- Add new argument of type: - - + Add new argument of type: + + + setArgs([...args, { type: 'object', value: objectIndex }]) + setObjectIndex(objectIndex + 1); + }}>object
args: {args.map((arg, index) => { // @ts-ignore return ( -
+
{ - args.splice(index,1); + args.splice(index, 1); setArgs([...args]); - }}/> - {index}: - {arg.type === 'string' ? - setArgs([ - ...args.slice(0, index), - {type: arg.type, value: e.target.value}, - ...args.slice(index + 1) - ])} - value={args[index].value || ''} - label="string" - key={`arg-${arg.type}-${index}`} - /> : arg.type === 'number' ? + }} /> + {index}: + {arg.type === 'string' ? setArgs([ ...args.slice(0, index), - {type: arg.type, value: Number(e.target.value)}, + { type: arg.type, value: e.target.value }, ...args.slice(index + 1) ])} value={args[index].value || ''} - label="number" - /> : - - //@ts-ignore - objectRefs.current[arg.value] = el} key={`arg-${arg.type}-${index}`}/> - } -
- )})} + label="string" + key={`arg-${arg.type}-${index}`} + /> : arg.type === 'number' ? + setArgs([ + ...args.slice(0, index), + { type: arg.type, value: Number(e.target.value) }, + ...args.slice(index + 1) + ])} + value={args[index].value || ''} + label="number" + /> : + + //@ts-ignore + objectRefs.current[arg.value] = el} key={`arg-${arg.type}-${index}`} /> + } +
+ ) + })}
-
+
) }