diff --git a/App.tsx b/App.tsx
index 3b42c75..a72629d 100644
--- a/App.tsx
+++ b/App.tsx
@@ -67,6 +67,27 @@ const App: React.FC = () => {
vendorStock: [],
});
+ const top50Mode = useMemo(() => {
+ const hasUK = filters.customer.includes('Amazon UK');
+ const hasEU = filters.customer.some(c => ['Amazon DE', 'Amazon IT', 'Amazon FR', 'Amazon ES'].includes(c));
+ if (hasUK) return 'uk';
+ return 'eu';
+ }, [filters.customer]);
+
+ // Calculate 4-week Sales Velocity Map (Context-Aware)
+ // MOVED HERE TO AVOID REFERENCE ERROR in handleForecastFetch
+ const velocityMap = useMemo(() => {
+ // Determine which dataset to use for velocity calculation based on region filter
+ // If 'uk', use UK data. If 'eu', use EU data.
+ // IMPOTANT: We do NOT filter by Week/Month here, so we get the full history for velocity calculation
+ const regionData = rawData.filter(r => {
+ if (top50Mode === 'uk') return r.customer.toLowerCase().includes('uk');
+ // for EU, exclude UK
+ return !r.customer.toLowerCase().includes('uk');
+ });
+ return calculateVelocityMap(regionData);
+ }, [rawData, top50Mode]);
+
// Handle Data Fetch (Simplified)
const handleDataFetch = useCallback(async () => {
setSyncing(true);
@@ -407,13 +428,6 @@ const App: React.FC = () => {
return metaMap;
}, [rawData]);
- const top50Mode = useMemo(() => {
- const hasUK = filters.customer.includes('Amazon UK');
- const hasEU = filters.customer.some(c => ['Amazon DE', 'Amazon IT', 'Amazon FR', 'Amazon ES'].includes(c));
- if (hasUK) return 'uk';
- return 'eu';
- }, [filters.customer]);
-
const filteredData = useMemo(() => filterData(rawData, filters, stockMap, vendorStockMap, top50Mode), [rawData, filters, stockMap, vendorStockMap, top50Mode]);
const filteredAdsData = useMemo(() => filterAdsData(adsData, filters, globalAsinMetadata, stockMap, vendorStockMap, top50Mode), [adsData, filters, globalAsinMetadata, stockMap, vendorStockMap, top50Mode]);
const aggregatedData = useMemo(() => aggregateData(filteredData), [filteredData]);
@@ -450,18 +464,7 @@ const App: React.FC = () => {
};
}, [rawData]);
- // Calculate 4-week Sales Velocity Map (Context-Aware)
- const velocityMap = useMemo(() => {
- // Determine which dataset to use for velocity calculation based on top50Mode (which reflects region filter)
- // If 'uk', use UK data. If 'eu', use EU data.
- // IMPOTANT: We do NOT filter by Week/Month here, so we get the full history for velocity calculation
- const regionData = rawData.filter(r => {
- if (top50Mode === 'uk') return r.customer.toLowerCase().includes('uk');
- // for EU, exclude UK
- return !r.customer.toLowerCase().includes('uk');
- });
- return calculateVelocityMap(regionData);
- }, [rawData, top50Mode]);
+ // Determine which dataset to use for velocity calculation based on top50Mode
// Combine Sales & Ads Data dynamically based on current filters
const combinedAdsData = useMemo(() => {
diff --git a/components/ForecastView.tsx b/components/ForecastView.tsx
index a6c8a57..974c0a2 100644
--- a/components/ForecastView.tsx
+++ b/components/ForecastView.tsx
@@ -73,7 +73,7 @@ const ForecastRow: React.FC<{
{stockMap && (
)}
- {/* */}
+