From 8809103a3b436ed530487ad72d501901dfa1d625 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sun, 27 Oct 2024 19:25:10 +0530 Subject: [PATCH] fix: revert --- src/components/organisms/BrowserWindow.tsx | 70 ++++++++-------------- 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/src/components/organisms/BrowserWindow.tsx b/src/components/organisms/BrowserWindow.tsx index e8be35d4..d0d31c05 100644 --- a/src/components/organisms/BrowserWindow.tsx +++ b/src/components/organisms/BrowserWindow.tsx @@ -2,11 +2,11 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useSocketStore } from '../../context/socket'; import { Button } from '@mui/material'; import Canvas from "../atoms/canvas"; +import { useBrowserDimensionsStore } from "../../context/browserDimensions"; import { Highlighter } from "../atoms/Highlighter"; import { GenericModal } from '../atoms/GenericModal'; import { useActionContext } from '../../context/browserActions'; import { useBrowserSteps, TextStep } from '../../context/browserSteps'; -import { useGlobalInfoStore } from "../../context/globalInfo" interface ElementInfo { tagName: string; @@ -64,7 +64,6 @@ export const BrowserWindow = () => { const [paginationSelector, setPaginationSelector] = useState(''); const { socket } = useSocketStore(); - const { notify } = useGlobalInfoStore() //const { width, height } = useBrowserDimensionsStore(); const { getText, getList, paginationMode, paginationType, limitMode } = useActionContext(); const { addTextStep, addListStep } = useBrowserSteps(); @@ -85,16 +84,10 @@ export const BrowserWindow = () => { }; const resetListState = useCallback(() => { - socket?.emit('listSelector', { selector: null }); setListSelector(null); setFields({}); setCurrentListId(null); - setPaginationSelector(''); - setHighlighterData(null); - setShowAttributeModal(false); - setSelectedElement(null); - setAttributeOptions([]); - }, [socket]); + }, []); useEffect(() => { if (!getList) { @@ -120,19 +113,10 @@ export const BrowserWindow = () => { } }, [screenShot, canvasRef, socket, screencastHandler]); - // Watch for changes in listSelector - // useEffect(() => { - // if (listSelector) { - // notify(`info`,`List selector updated to: ${listSelector}`); - // // socket?.emit('listSelector', { selector: listSelector }); - // } - // }, [listSelector, socket]); - const highlighterHandler = useCallback((data: { rect: DOMRect, selector: string, elementInfo: ElementInfo | null, childSelectors?: string[] }) => { if (getList === true) { if (listSelector) { socket?.emit('listSelector', { selector: listSelector }); - notify(`info`, `List Selected. Proceed to select text you want to extract.`); if (limitMode) { setHighlighterData(null); } else if (paginationMode) { @@ -150,16 +134,14 @@ export const BrowserWindow = () => { setHighlighterData(null); } } else { - // Clear any existing highlighter data before setting new data - // This ensures we start fresh when selecting a new list selector - setHighlighterData(null); - setTimeout(() => setHighlighterData(data), 0); + // set highlighterData for the initial listSelector selection + setHighlighterData(data); } } else { // for non-list steps setHighlighterData(data); } - }, [getList, socket, listSelector, paginationMode, paginationType, limitMode]); + }, [highlighterData, getList, socket, listSelector, paginationMode, paginationType]); useEffect(() => { @@ -221,19 +203,19 @@ export const BrowserWindow = () => { } return; } - if (getList === true) { - if (!listSelector) { - setFields({}); - setPaginationSelector(''); + + if (getList === true && !listSelector) { setListSelector(highlighterData.selector); setCurrentListId(Date.now()); + setFields({}); } else if (getList === true && listSelector && currentListId) { + const attribute = options[0].value; + const data = attribute === 'href' ? highlighterData.elementInfo?.url || '' : + attribute === 'src' ? highlighterData.elementInfo?.imageUrl || '' : + highlighterData.elementInfo?.innerText || ''; // Add fields to the list if (options.length === 1) { const attribute = options[0].value; - const data = attribute === 'href' ? highlighterData.elementInfo?.url || '' : - attribute === 'src' ? highlighterData.elementInfo?.imageUrl || '' : - highlighterData.elementInfo?.innerText || ''; const newField: TextStep = { id: Date.now(), type: 'text', @@ -267,7 +249,7 @@ export const BrowserWindow = () => { setShowAttributeModal(true); } } - } } + } } }; @@ -334,7 +316,7 @@ export const BrowserWindow = () => { return ( -
+
{ getText === true || getList === true ? ( { ) : null }
- {((getText === true || getList === true) && !showAttributeModal && highlighterData?.rect != null && highlighterData?.rect.top != null) && canvasRef?.current ? - + : null} + - : null} -
); @@ -419,4 +401,4 @@ const modalStyle = { height: 'fit-content', display: 'block', padding: '20px', - }; \ No newline at end of file +}; \ No newline at end of file