mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 14:45:24 +02:00
Optimize app loading and fix product lines in experiments
Performance improvements: - Fetch traffic, stock, vendor stock, buybox, and experiments data in parallel using Promise.all - Reduces initial loading time significantly - Non-blocking background fetches after sales data loads Bug fixes: - Pass availableLines from App.tsx to ExperimentForm as prop - Remove localStorage dependency for product lines - Product lines now correctly populated from rawData Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
co-authored by
Qwen-Coder
parent
5efc2d519e
commit
d535004a29
@@ -67,6 +67,12 @@ const App: React.FC = () => {
|
|||||||
const [preselectedMarketplace, setPreselectedMarketplace] = useState<string>('');
|
const [preselectedMarketplace, setPreselectedMarketplace] = useState<string>('');
|
||||||
const [preselectedLine, setPreselectedLine] = useState<string>('');
|
const [preselectedLine, setPreselectedLine] = useState<string>('');
|
||||||
|
|
||||||
|
// 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
|
// Modal State
|
||||||
const [isDataModalOpen, setIsDataModalOpen] = useState(false);
|
const [isDataModalOpen, setIsDataModalOpen] = useState(false);
|
||||||
|
|
||||||
@@ -400,19 +406,14 @@ const App: React.FC = () => {
|
|||||||
handleAdsFetch();
|
handleAdsFetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1c. Always fetch Traffic data (no caching for now)
|
// 1c-1f. Fetch other data in parallel (non-blocking)
|
||||||
console.log("Fetching Traffic data...");
|
Promise.all([
|
||||||
handleTrafficFetch();
|
handleTrafficFetch(),
|
||||||
|
handleStockFetch(),
|
||||||
// 1d. Always fetch Stock data
|
handleVendorStockFetch(),
|
||||||
console.log("Fetching Stock data...");
|
handleBuyBoxFetch(),
|
||||||
handleStockFetch();
|
handleExperimentsFetch()
|
||||||
handleVendorStockFetch();
|
]).catch(e => console.warn("Background fetch failed", e));
|
||||||
handleBuyBoxFetch();
|
|
||||||
|
|
||||||
// 1e. Fetch Experiments data
|
|
||||||
console.log("Fetching Experiments data...");
|
|
||||||
handleExperimentsFetch();
|
|
||||||
|
|
||||||
// 1f. Fetch Forecast data
|
// 1f. Fetch Forecast data
|
||||||
handleForecastFetch(cachedData || [], cachedData || [], filters);
|
handleForecastFetch(cachedData || [], cachedData || [], filters);
|
||||||
@@ -1051,6 +1052,7 @@ const App: React.FC = () => {
|
|||||||
initialAsins={preselectedAsins}
|
initialAsins={preselectedAsins}
|
||||||
initialMarketplace={preselectedMarketplace}
|
initialMarketplace={preselectedMarketplace}
|
||||||
initialLine={preselectedLine}
|
initialLine={preselectedLine}
|
||||||
|
availableLines={availableProductLines}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ interface ExperimentFormProps {
|
|||||||
initialAsins?: string[];
|
initialAsins?: string[];
|
||||||
initialMarketplace?: string;
|
initialMarketplace?: string;
|
||||||
initialLine?: string;
|
initialLine?: string;
|
||||||
|
availableLines?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const ExperimentForm: React.FC<ExperimentFormProps> = ({
|
const ExperimentForm: React.FC<ExperimentFormProps> = ({
|
||||||
@@ -15,7 +16,8 @@ const ExperimentForm: React.FC<ExperimentFormProps> = ({
|
|||||||
onSuccess,
|
onSuccess,
|
||||||
initialAsins = [],
|
initialAsins = [],
|
||||||
initialMarketplace = 'DE',
|
initialMarketplace = 'DE',
|
||||||
initialLine = ''
|
initialLine = '',
|
||||||
|
availableLines = []
|
||||||
}) => {
|
}) => {
|
||||||
const [formData, setFormData] = useState<ExperimentCreateInput>({
|
const [formData, setFormData] = useState<ExperimentCreateInput>({
|
||||||
name: '',
|
name: '',
|
||||||
@@ -36,21 +38,6 @@ const ExperimentForm: React.FC<ExperimentFormProps> = ({
|
|||||||
const [targetType, setTargetType] = useState<'asin' | 'line'>(initialAsins.length > 0 ? 'asin' : initialLine ? 'line' : 'asin');
|
const [targetType, setTargetType] = useState<'asin' | 'line'>(initialAsins.length > 0 ? 'asin' : initialLine ? 'line' : 'asin');
|
||||||
const [selectedLine, setSelectedLine] = useState(initialLine);
|
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 = () => {
|
const handleAddAsin = () => {
|
||||||
// Support both comma and space separated ASINs
|
// Support both comma and space separated ASINs
|
||||||
const newAsins = asinInput
|
const newAsins = asinInput
|
||||||
|
|||||||
Reference in New Issue
Block a user