diff --git a/App.tsx b/App.tsx index b768c9b..4116df3 100644 --- a/App.tsx +++ b/App.tsx @@ -66,6 +66,12 @@ const App: React.FC = () => { const [preselectedAsins, setPreselectedAsins] = useState([]); const [preselectedMarketplace, setPreselectedMarketplace] = useState(''); const [preselectedLine, setPreselectedLine] = useState(''); + + // Available product lines (for experiment form) + const availableProductLines = useMemo(() => { + const lines = new Set(rawData.map(r => r.line).filter(Boolean)); + return Array.from(lines).sort(); + }, [rawData]); // Modal State const [isDataModalOpen, setIsDataModalOpen] = useState(false); @@ -400,19 +406,14 @@ const App: React.FC = () => { handleAdsFetch(); } - // 1c. Always fetch Traffic data (no caching for now) - console.log("Fetching Traffic data..."); - handleTrafficFetch(); - - // 1d. Always fetch Stock data - console.log("Fetching Stock data..."); - handleStockFetch(); - handleVendorStockFetch(); - handleBuyBoxFetch(); - - // 1e. Fetch Experiments data - console.log("Fetching Experiments data..."); - handleExperimentsFetch(); + // 1c-1f. Fetch other data in parallel (non-blocking) + Promise.all([ + handleTrafficFetch(), + handleStockFetch(), + handleVendorStockFetch(), + handleBuyBoxFetch(), + handleExperimentsFetch() + ]).catch(e => console.warn("Background fetch failed", e)); // 1f. Fetch Forecast data handleForecastFetch(cachedData || [], cachedData || [], filters); @@ -1051,6 +1052,7 @@ const App: React.FC = () => { initialAsins={preselectedAsins} initialMarketplace={preselectedMarketplace} initialLine={preselectedLine} + availableLines={availableProductLines} /> )} diff --git a/components/ExperimentForm.tsx b/components/ExperimentForm.tsx index be903a8..1f10f7e 100644 --- a/components/ExperimentForm.tsx +++ b/components/ExperimentForm.tsx @@ -8,6 +8,7 @@ interface ExperimentFormProps { initialAsins?: string[]; initialMarketplace?: string; initialLine?: string; + availableLines?: string[]; } const ExperimentForm: React.FC = ({ @@ -15,7 +16,8 @@ const ExperimentForm: React.FC = ({ onSuccess, initialAsins = [], initialMarketplace = 'DE', - initialLine = '' + initialLine = '', + availableLines = [] }) => { const [formData, setFormData] = useState({ name: '', @@ -36,21 +38,6 @@ const ExperimentForm: React.FC = ({ const [targetType, setTargetType] = useState<'asin' | 'line'>(initialAsins.length > 0 ? 'asin' : initialLine ? 'line' : 'asin'); const [selectedLine, setSelectedLine] = useState(initialLine); - // Get available product lines from localStorage (sales data) - const availableLines = useMemo(() => { - try { - const cachedData = localStorage.getItem('craze_sales_data'); - if (cachedData) { - const data = JSON.parse(cachedData); - const lines = new Set(data.map((r: any) => r.line).filter(Boolean)); - return Array.from(lines).sort(); - } - } catch (e) { - console.error('Failed to load product lines:', e); - } - return []; - }, []); - const handleAddAsin = () => { // Support both comma and space separated ASINs const newAsins = asinInput