diff --git a/src/components/organisms/RightSidePanel.tsx b/src/components/organisms/RightSidePanel.tsx index 9168f6a8..c7ba1b9f 100644 --- a/src/components/organisms/RightSidePanel.tsx +++ b/src/components/organisms/RightSidePanel.tsx @@ -13,7 +13,7 @@ export const RightSidePanel = () => { const [textLabels, setTextLabels] = useState<{ [id: number]: string }>({}); const [errors, setErrors] = useState<{ [id: number]: string }>({}); const [confirmedTextSteps, setConfirmedTextSteps] = useState<{ [id: number]: boolean }>({}); - + const { lastAction } = useGlobalInfoStore(); const { getText, getScreenshot, startGetText, stopGetText, startGetScreenshot, stopGetScreenshot } = useActionContext(); const { browserSteps, updateBrowserTextStepLabel, deleteBrowserStep, addScreenshotStep } = useBrowserSteps(); @@ -21,10 +21,11 @@ export const RightSidePanel = () => { const handleTextLabelChange = (id: number, label: string) => { setTextLabels(prevLabels => ({ ...prevLabels, [id]: label })); - setErrors(prevErrors => ({ - ...prevErrors, - [id]: label.trim() ? '' : 'Label cannot be empty' - })); + if (!label.trim()) { + setErrors(prevErrors => ({ ...prevErrors, [id]: 'Label cannot be empty' })); + } else { + setErrors(prevErrors => ({ ...prevErrors, [id]: '' })); + } }; const handleTextStepConfirm = (id: number) => { @@ -50,7 +51,7 @@ export const RightSidePanel = () => { }; const getTextSettingsObject = useCallback(() => { - const settings: Record = {}; + const settings: Record = {}; browserSteps.forEach(step => { if (step.type === 'text' && step.label && step.selectorObj?.selector) { settings[step.label] = step.selectorObj; @@ -59,6 +60,7 @@ export const RightSidePanel = () => { return settings; }, [browserSteps]); + const stopCaptureAndEmitGetTextSettings = useCallback(() => { stopGetText(); const settings = getTextSettingsObject(); @@ -68,6 +70,7 @@ export const RightSidePanel = () => { } }, [stopGetText, getTextSettingsObject, socket, browserSteps]); + const captureScreenshot = (fullPage: boolean) => { const screenshotSettings: ScreenshotSettings = { fullPage, @@ -81,14 +84,6 @@ export const RightSidePanel = () => { addScreenshotStep(fullPage); }; - const handleBack = () => { - if (getText) { - stopGetText(); - } else if (getScreenshot) { - stopGetScreenshot(); - } - }; - return ( @@ -97,60 +92,56 @@ export const RightSidePanel = () => { {!getText && !getScreenshot && } - {getText && } + {getText && } {!getText && !getScreenshot && } {getScreenshot && ( + )} - - - - - - {browserSteps.map(step => ( - {step.type === 'text' ? ( - <> - handleTextLabelChange(step.id, e.target.value)} - fullWidth - margin="normal" - error={!!errors[step.id]} - helperText={errors[step.id]} - InputProps={{ readOnly: confirmedTextSteps[step.id] }} - /> - - {!confirmedTextSteps[step.id] && ( - - - - - )} - - ) : ( - step.type === 'screenshot' && ( - {`Take ${step.fullPage ? 'Fullpage' : 'Visible Part'} Screenshot`} + { + step.type === 'text' ? ( + <> + handleTextLabelChange(step.id, e.target.value)} + fullWidth + margin="normal" + error={!!errors[step.id]} + helperText={errors[step.id]} + InputProps={{ readOnly: confirmedTextSteps[step.id] }} + /> + + {!confirmedTextSteps[step.id] && ( + + + + + )} + + ) : ( + step.type === 'screenshot' && ( + {`Take ${step.fullPage ? 'Fullpage' : 'Visible Part'} Screenshot`} + ) ) - )} + } ))} - ); };