adds activity indicators in header (ugly af)

This commit is contained in:
2025-02-11 01:58:06 +01:00
parent 0340dea4f8
commit 57e969a647
7 changed files with 234 additions and 92 deletions

View File

@@ -1,36 +1,21 @@
import { ScraperUtils } from './scraper_utils.js';
class ScraperApp {
constructor() {
this.utils = new ScraperUtils();
this.form = document.getElementById('scrapingForm');
this.stopButton = document.getElementById('stopButton');
this.startButton = document.getElementById('startButton');
this.activityIndicator = document.getElementById('activity_indicator');
this.endTimeElement = document.getElementById('end_time');
this.init();
}
init() {
this.checkScrapingStatusIndex();
this.utils.checkScrapingStatus();
this.addEventListeners();
}
async checkScrapingStatusIndex() {
try {
const response = await fetch('/scraping_status');
const data = await response.json();
if (data.scraping_active) {
this.startButton.disabled = true;
this.stopButton.disabled = false;
} else {
this.startButton.disabled = false;
this.stopButton.disabled = true;
}
} catch (error) {
console.error('Error checking scraping status:', error);
}
}
async startScraping(event) {
event.preventDefault(); // Prevent the default form submission
event.preventDefault(); // Prevent default form submission
const formData = new FormData(this.form);
try {
const response = await fetch('/start_scraping', {
@@ -39,7 +24,7 @@ class ScraperApp {
});
const data = await response.json();
if (data.status === "Scraping started") {
this.checkScrapingStatusIndex();
this.utils.checkScrapingStatus(); // Update UI
}
} catch (error) {
console.error('Error starting scraping:', error);
@@ -53,7 +38,7 @@ class ScraperApp {
});
const data = await response.json();
if (data.status === "Scraping stopped") {
this.checkScrapingStatusIndex();
this.utils.checkScrapingStatus(); // Update UI
}
} catch (error) {
console.error('Error stopping scraping:', error);
@@ -66,7 +51,6 @@ class ScraperApp {
}
}
// Initialize the application when DOM is fully loaded
document.addEventListener('DOMContentLoaded', () => {
new ScraperApp();
});
});