feat: auto-load Traffic data from Dropbox on app startup

- api/fetch-traffic.ts: New endpoint to fetch Traffic Weekly.xlsx from Dropbox
- App.tsx: Added handleTrafficFetch function and auto-fetch on initialization
This commit is contained in:
Christian Vidal Wolf
2026-01-23 09:23:42 +01:00
parent affae9e994
commit 7a0375fca7
2 changed files with 55 additions and 0 deletions
+23
View File
@@ -119,6 +119,25 @@ const App: React.FC = () => {
}
}, []);
const handleTrafficFetch = useCallback(async () => {
try {
console.log('[App] Fetching traffic from /api/fetch-traffic...');
const response = await fetch('/api/fetch-traffic');
if (!response.ok) {
throw new Error(`Failed to fetch Traffic: ${response.status} ${response.statusText}`);
}
const buffer = await response.arrayBuffer();
const data = await processTrafficExcel(buffer);
setTrafficData(data);
console.log('[App] Successfully loaded', data.length, 'traffic records');
} catch (error) {
console.error("Failed to fetch/parse Traffic", error);
}
}, []);
const initializeData = (data: SalesRecord[]) => {
setRawData(data);
setFilters({
@@ -188,6 +207,10 @@ const App: React.FC = () => {
console.log("Fetching fresh Ads from URL...");
handleAdsFetch();
}
// 1c. Always fetch Traffic data (no caching for now)
console.log("Fetching Traffic data...");
handleTrafficFetch();
};
initApp();
}, [handleDataFetch]);