diff --git a/src/components/organisms/BrowserWindow.tsx b/src/components/organisms/BrowserWindow.tsx index 29c215f0..f6afaacc 100644 --- a/src/components/organisms/BrowserWindow.tsx +++ b/src/components/organisms/BrowserWindow.tsx @@ -197,61 +197,67 @@ export const BrowserWindow = () => { } } - if (paginationMode && getList) { - // Only allow selection in pagination mode if type is not empty, 'scrollDown', or 'scrollUp' - if (paginationType !== '' && paginationType !== 'scrollDown' && paginationType !== 'scrollUp' && paginationType !== 'none') { - setPaginationSelector(highlighterData.selector); - addListStep(listSelector!, fields, currentListId || 0, { type: paginationType, selector: highlighterData.selector }); - } - return; - } - - if (getList === true && !listSelector) { - setListSelector(highlighterData.selector); - notify(`info`, `List selected succesfully. Select the text data for extraction.`) - 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 newField: TextStep = { - id: Date.now(), - type: 'text', - label: `Label ${Object.keys(fields).length + 1}`, - data: data, - selectorObj: { - selector: highlighterData.selector, - tag: highlighterData.elementInfo?.tagName, - attribute - } - }; - - setFields(prevFields => { - const updatedFields = { - ...prevFields, - [newField.id]: newField - }; - return updatedFields; - }); - - if (listSelector) { - addListStep(listSelector, { ...fields, [newField.id]: newField }, currentListId, { type: '', selector: paginationSelector }); + if (getList === true) { + // Handle pagination mode logic only when a list is being processed + if (paginationMode) { + // Only allow selection in pagination mode if type is not empty, 'scrollDown', or 'scrollUp' + if (paginationType !== '' && paginationType !== 'scrollDown' && paginationType !== 'scrollUp' && paginationType !== 'none') { + setPaginationSelector(highlighterData.selector); + addListStep(listSelector!, fields, currentListId || 0, { type: paginationType, selector: highlighterData.selector }); + } + return; + } + + // If no listSelector is set yet, set the listSelector + if (!listSelector) { + setListSelector(highlighterData.selector); + notify(`info`, `List selected successfully. Select the text data for extraction.`); + setCurrentListId(Date.now()); + setFields({}); + } else if (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 newField: TextStep = { + id: Date.now(), + type: 'text', + label: `Label ${Object.keys(fields).length + 1}`, + data: data, + selectorObj: { + selector: highlighterData.selector, + tag: highlighterData.elementInfo?.tagName, + attribute + } + }; + + setFields(prevFields => { + const updatedFields = { + ...prevFields, + [newField.id]: newField + }; + return updatedFields; + }); + + // Add new field and update the list step + if (listSelector) { + addListStep(listSelector, { ...fields, [newField.id]: newField }, currentListId, { type: '', selector: paginationSelector }); + } + + } else { + setAttributeOptions(options); + setSelectedElement({ + selector: highlighterData.selector, + info: highlighterData.elementInfo + }); + setShowAttributeModal(true); } - - } else { - setAttributeOptions(options); - setSelectedElement({ - selector: highlighterData.selector, - info: highlighterData.elementInfo - }); - setShowAttributeModal(true); } } + } } };