diff --git a/src/components/molecules/InterpretationButtons.tsx b/src/components/molecules/InterpretationButtons.tsx index c9f45be2..d57a3b1c 100644 --- a/src/components/molecules/InterpretationButtons.tsx +++ b/src/components/molecules/InterpretationButtons.tsx @@ -1,5 +1,5 @@ -import { Box, Button, IconButton, Stack, Typography } from "@mui/material"; -import { PauseCircle, PlayCircle, StopCircle } from "@mui/icons-material"; +import { Box, Button, Stack, Typography } from "@mui/material"; +import { PlayCircle } from "@mui/icons-material"; import React, { useCallback, useEffect, useState } from "react"; import { interpretCurrentRecording, stopCurrentInterpretation } from "../../api/recording"; import { useSocketStore } from "../../context/socket"; @@ -20,10 +20,10 @@ interface InterpretationInfo { const interpretationInfo: InterpretationInfo = { running: false, isPaused: false, -} +}; export const InterpretationButtons = ({ enableStepping }: InterpretationButtonsProps) => { - const [info, setInfo] = React.useState(interpretationInfo); + const [info, setInfo] = useState(interpretationInfo); const [decisionModal, setDecisionModal] = useState<{ pair: WhereWhatPair | null, actionType: string, @@ -44,52 +44,47 @@ export const InterpretationButtons = ({ enableStepping }: InterpretationButtonsP const breakpointHitHandler = useCallback(() => { setInfo({ running: false, isPaused: true }); - notify('warning', 'Please restart the interpretation, after updating the recording'); + notify('warning', 'Please restart the interpretation after updating the recording'); enableStepping(true); - }, [info, enableStepping]); + }, [enableStepping]); const decisionHandler = useCallback( - ({ pair, actionType, lastData } - : { pair: WhereWhatPair | null, actionType: string, lastData: { selector: string, action: string, tagName: string, innerText: string } }) => { + ({ pair, actionType, lastData }: { pair: WhereWhatPair | null, actionType: string, lastData: { selector: string, action: string, tagName: string, innerText: string } }) => { const { selector, action, tagName, innerText } = lastData; - setDecisionModal((prevState) => { - return { - pair, - actionType, - selector, - action, - tagName, - innerText, - open: true, - } - }) - }, [decisionModal]); + setDecisionModal((prevState) => ({ + pair, + actionType, + selector, + action, + tagName, + innerText, + open: true, + })); + }, []); const handleDecision = (decision: boolean) => { const { pair, actionType } = decisionModal; socket?.emit('decision', { pair, actionType, decision }); setDecisionModal({ pair: null, actionType: '', selector: '', action: '', tagName: '', innerText: '', open: false }); - } + }; const handleDescription = () => { - switch (decisionModal.actionType) { - case 'customAction': - return ( - + if (decisionModal.actionType === 'customAction') { + return ( + <> + + Do you want to use your previous selection as a condition for performing this action? + + - Do you want to use your previous selection as a condition for performing this action? + Your previous action was: {decisionModal.action}, on an element with text {decisionModal.innerText} - - Your previous action was: - {decisionModal.action.charAt(0).toUpperCase() + decisionModal.action.slice(1)} , - on an element with text - {decisionModal.innerText} - - - ); - default: return null; + + + ); } - } + return null; + }; useEffect(() => { if (socket) { @@ -101,15 +96,11 @@ export const InterpretationButtons = ({ enableStepping }: InterpretationButtonsP socket?.off('finished', finishedHandler); socket?.off('breakpointHit', breakpointHitHandler); socket?.off('decision', decisionHandler); - } + }; }, [socket, finishedHandler, breakpointHitHandler]); const handlePlay = async () => { - if (info.isPaused) { - socket?.emit("resume"); - setInfo({ running: true, isPaused: false }); - enableStepping(false); - } else { + if (!info.running) { setInfo({ ...info, running: true }); const finished = await interpretCurrentRecording(); setInfo({ ...info, running: false }); @@ -121,40 +112,39 @@ export const InterpretationButtons = ({ enableStepping }: InterpretationButtonsP } }; + // pause and stop logic (do not delete - we wil bring this back!) + /* + const handlePause = async () => { + if (info.running) { + socket?.emit("pause"); + setInfo({ running: false, isPaused: true }); + notify('warning', 'Please restart the interpretation after updating the recording'); + enableStepping(true); + } + }; + const handleStop = async () => { setInfo({ running: false, isPaused: false }); enableStepping(false); await stopCurrentInterpretation(); }; - - const handlePause = async () => { - if (info.running) { - socket?.emit("pause"); - setInfo({ running: false, isPaused: true }); - notify('warning', 'Please restart the interpretation, after updating the recording'); - enableStepping(true); - } - }; + */ return ( - - - - Pause - - - - {info.isPaused ? 'Resume' : 'Start'} - - - - Stop - - { }} isOpen={decisionModal.open} canBeClosed={false} + + + { }} + isOpen={decisionModal.open} + canBeClosed={false} modalStyle={{ position: 'absolute', top: '50%', @@ -168,15 +158,14 @@ export const InterpretationButtons = ({ enableStepping }: InterpretationButtonsP display: 'block', overflow: 'scroll', padding: '5px 25px 10px 25px', - }}> + }} + >
- { - handleDescription() - } + {handleDescription()}
- - + +