mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 11:55:22 +02:00
fix: update data source URL and force refresh on change
This commit is contained in:
@@ -23,7 +23,7 @@ const RefreshIcon = ({ className }: { className?: string }) => (
|
||||
|
||||
// Hardcoded Permanent URL for Auto-Loading
|
||||
// Using the original share link to leverage Dropbox's redirect for robust fetching.
|
||||
const PERMANENT_DROPBOX_URL = "https://www.dropbox.com/scl/fi/b9zxn4z5i7sxwfakk5g5y/Amazon-Sell-Out-2023-2025.csv?rlkey=uoto6v0mm99py8nszy8ldtez8&st=7vk22iod&dl=0";
|
||||
const PERMANENT_DROPBOX_URL = "https://www.dropbox.com/scl/fi/b9zxn4z5i7sxwfakk5g5y/Amazon-Sell-Out-2023-2025.csv?rlkey=uoto6v0mm99py8nszy8ldtez8&st=pzn1zkrg&dl=0";
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [rawData, setRawData] = useState<SalesRecord[]>([]);
|
||||
@@ -118,20 +118,32 @@ const App: React.FC = () => {
|
||||
setLoading(true);
|
||||
|
||||
const currentStoredUrl = localStorage.getItem('craze_csv_url');
|
||||
let shouldUseCache = true;
|
||||
|
||||
// Force refresh if URL has changed
|
||||
if (currentStoredUrl !== PERMANENT_DROPBOX_URL) {
|
||||
console.log("URL changed, forcing refresh...");
|
||||
localStorage.setItem('craze_csv_url', PERMANENT_DROPBOX_URL);
|
||||
setActiveUrl(PERMANENT_DROPBOX_URL);
|
||||
shouldUseCache = false;
|
||||
}
|
||||
|
||||
const { data, lastUpdated: date } = await loadSalesData();
|
||||
// Try to load from cache first IF the URL hasn't changed
|
||||
let cachedData = null;
|
||||
let cachedDate = null;
|
||||
if (shouldUseCache) {
|
||||
const result = await loadSalesData();
|
||||
cachedData = result.data;
|
||||
cachedDate = result.lastUpdated;
|
||||
}
|
||||
|
||||
if (data && data.length > 0) {
|
||||
console.log("Loaded data from cache:", data.length, "rows");
|
||||
initializeData(data);
|
||||
setLastUpdated(date);
|
||||
if (cachedData && cachedData.length > 0) {
|
||||
console.log("Loaded data from cache:", cachedData.length, "rows");
|
||||
initializeData(cachedData);
|
||||
setLastUpdated(cachedDate);
|
||||
setLoading(false);
|
||||
} else {
|
||||
console.log("No cache found. Auto-fetching from Permanent URL...");
|
||||
console.log("Fetching fresh data from Permanent URL...");
|
||||
handleUrlFetch(PERMANENT_DROPBOX_URL).catch(e => {
|
||||
console.error("Initial fetch failed.");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user