From 19fbd12e772f799be4c2daaa20d7790613a92d72 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Tue, 27 Jan 2026 15:02:18 +0100 Subject: [PATCH] Auto-Sync and Manual Refresh: Ensured fresh data on reload and added Sync button --- App.tsx | 35 ++++++++++++++++++++++++++++------- api/fetch-ads.ts | 8 +++++++- api/fetch-data.ts | 8 +++++++- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/App.tsx b/App.tsx index fe46664..baf34a5 100644 --- a/App.tsx +++ b/App.tsx @@ -240,6 +240,8 @@ const App: React.FC = () => { initializeData(cachedData); setLastUpdated(cachedDate); setLoading(false); + // Trigger background sync to ensure data is fresh + handleDataFetch().catch(e => console.warn("Background sales sync failed", e)); } else { console.log("Fetching fresh data from Permanent URL..."); handleDataFetch().catch(e => { @@ -252,6 +254,8 @@ const App: React.FC = () => { if (cachedAds && cachedAds.length > 0) { console.log("Loaded ads from cache:", cachedAds.length, "records"); setAdsData(cachedAds); + // Trigger background sync + handleAdsFetch(); } else { console.log("Fetching fresh Ads from URL..."); handleAdsFetch(); @@ -481,16 +485,33 @@ const App: React.FC = () => { {/* Title & Status */}

Analytics Dashboard

- {activeUrl && lastUpdated && ( -

- - Live Sync Active -

- )} +
+
+ + Live Sync +
+ {lastUpdated && ( + + Last: {new Date(lastUpdated).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} + + )} +
-
+
+ {/* Force Sync Action */} + {/* View Switcher is the priority now */} {/* View Switcher */}
diff --git a/api/fetch-ads.ts b/api/fetch-ads.ts index 56f991f..5c9ea40 100644 --- a/api/fetch-ads.ts +++ b/api/fetch-ads.ts @@ -14,7 +14,13 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { try { console.log('[fetch-ads] Fetching Ads from Dropbox...'); - const response = await fetch(ADS_DROPBOX_URL); + const response = await fetch(ADS_DROPBOX_URL, { + cache: 'no-store', + headers: { + 'Pragma': 'no-cache', + 'Cache-Control': 'no-cache' + } + }); if (!response.ok) { throw new Error(`Dropbox responded with ${response.status}`); diff --git a/api/fetch-data.ts b/api/fetch-data.ts index 584e4c9..52100f2 100644 --- a/api/fetch-data.ts +++ b/api/fetch-data.ts @@ -14,7 +14,13 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { try { console.log('[fetch-data] Fetching from Dropbox...'); - const response = await fetch(DROPBOX_URL); + const response = await fetch(DROPBOX_URL, { + cache: 'no-store', + headers: { + 'Pragma': 'no-cache', + 'Cache-Control': 'no-cache' + } + }); if (!response.ok) { throw new Error(`Dropbox responded with ${response.status}`);