mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:35:24 +02:00
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:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user