diff --git a/fotograf-de-scraper/frontend/src/App.tsx b/fotograf-de-scraper/frontend/src/App.tsx index 97d6e9b2..5e2326c8 100644 --- a/fotograf-de-scraper/frontend/src/App.tsx +++ b/fotograf-de-scraper/frontend/src/App.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react'; +import { useState } from 'react'; import './App.css'; interface Job { @@ -10,25 +10,31 @@ interface Job { shooting_type: string; } +type AccountType = 'kiga' | 'schule'; + function App() { - const [accountType, setAccountType] = useState('kiga'); // Default to kindergarten - const [jobs, setJobs] = useState([]); + const [activeTab, setActiveTab] = useState('kiga'); + // Cache to store loaded jobs so we don't reload when switching tabs + const [jobsCache, setJobsCache] = useState>({ + kiga: null, + schule: null, + }); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://192.168.178.6:8002'; - const fetchJobs = async () => { + const fetchJobs = async (account: AccountType) => { setIsLoading(true); setError(null); try { - const response = await fetch(`${API_BASE_URL}/api/jobs?account_type=${accountType}`); + const response = await fetch(`${API_BASE_URL}/api/jobs?account_type=${account}`); if (!response.ok) { const errData = await response.json(); throw new Error(errData.detail || 'Fehler beim Abrufen der Aufträge'); } const data: Job[] = await response.json(); - setJobs(data); + setJobsCache(prev => ({ ...prev, [account]: data })); } catch (err: any) { setError(err.message); console.error("Failed to fetch jobs:", err); @@ -37,63 +43,123 @@ function App() { } }; - useEffect(() => { - fetchJobs(); - }, [accountType]); // Refetch when accountType changes + const handleRefresh = () => { + fetchJobs(activeTab); + }; + + const currentJobs = jobsCache[activeTab]; return ( -
-
-

Fotograf.de Auftragsübersicht

+
+
+

Fotograf.de ERP & Scraper

-
- - + 📸 Kindergarten Fotografie + +
- + {/* Status and Refresh Area */} +
+

+ {currentJobs === null + ? "Aufträge wurden noch nicht geladen." + : `${currentJobs.length} Aufträge geladen.`} +

+ +
- {error &&

Fehler: {error}

} - - {jobs.length === 0 && !isLoading && !error && ( -

Keine Aufträge gefunden.

+ {error && ( +
+

Fehler beim Scrapen:

+

{error}

+
)} - {jobs.length > 0 && ( -
+ {currentJobs !== null && currentJobs.length === 0 && !isLoading && !error && ( +
+

Keine Aufträge in diesem Account gefunden.

+
+ )} + + {/* Jobs Table */} + {currentJobs !== null && currentJobs.length > 0 && ( +
- + - - - - - + + + - {jobs.map((job) => ( - - - - - - + + + + {/* Actions Column */} + ))} @@ -106,4 +172,4 @@ function App() { ); } -export default App; \ No newline at end of file +export default App;
NameStatusDatumTypAktionenName des AuftragsDatumFeatures & Aktionen
{job.name}{job.status}{job.date}{job.shooting_type} - Details + {currentJobs.map((job) => ( +
+ + {job.name} + +
Status: {job.status}
+
{job.date} +
+ + + + + + + + + +