diff --git a/src/App.js b/src/App.js index cb46226..2e2aa26 100644 --- a/src/App.js +++ b/src/App.js @@ -228,32 +228,38 @@ const WebScraper = () => { } }; - const startScraping = async () => { - if (!selectedSession) return; - + const startScrapingById = async (sessionId, sessionName) => { try { - await fetch(`${API_BASE}/sessions/${selectedSession.sessionId}/scrap/start`, { + await fetch(`${API_BASE}/sessions/${sessionId}/scrap/start`, { method: 'POST' }); - addLog(`Iniciando scraping da sessão: ${selectedSession.name}`, 'info'); + addLog(`Iniciando scraping da sessão: ${sessionName}`, 'info'); } catch (err) { addLog(`Erro ao iniciar: ${err.message}`, 'error'); } }; - const stopScraping = async () => { - if (!selectedSession) return; - + const stopScrapingById = async (sessionId, sessionName) => { try { - await fetch(`${API_BASE}/sessions/${selectedSession.sessionId}/scrap/stop`, { + await fetch(`${API_BASE}/sessions/${sessionId}/scrap/stop`, { method: 'POST' }); - addLog(`Parando sessão: ${selectedSession.name}`, 'warning'); + addLog(`Parando sessão: ${sessionName}`, 'warning'); } catch (err) { addLog(`Erro ao parar: ${err.message}`, 'error'); } }; + const startScraping = async () => { + if (!selectedSession) return; + await startScrapingById(selectedSession.sessionId, selectedSession.name); + }; + + const stopScraping = async () => { + if (!selectedSession) return; + await stopScrapingById(selectedSession.sessionId, selectedSession.name); + }; + const addUrlToQueue = async () => { if (!selectedSession || !newUrl) return; @@ -335,6 +341,15 @@ const WebScraper = () => { return total > 0 ? ((done / total) * 100).toFixed(1) : 0; }; + const handleSessionAction = (e, session) => { + e.stopPropagation(); // Evita selecionar a sessão ao clicar no botão + if (session.isRunning) { + stopScrapingById(session.sessionId, session.name); + } else { + startScrapingById(session.sessionId, session.name); + } + }; + return (