Hydrate homepage market data

This commit is contained in:
2569718930@qq.com
2026-04-23 00:02:25 +08:00
parent 5dcf98b810
commit c3ca20c849
4 changed files with 88 additions and 11 deletions
+40
View File
@@ -555,6 +555,31 @@ export function DashboardStoreProvider({
return detail;
};
const ensureCityMarketScan = async (cityName: string, force = false) => {
const cached = cityDetailsByName[cityName];
try {
const payload = await dashboardClient.getCityMarketScan(cityName, {
force,
targetDate: cached?.local_date || selectedForecastDate || null,
});
if (!payload.market_scan) return null;
setCityDetailsByName((current) => {
const detail = current[cityName];
if (!detail) return current;
return {
...current,
[cityName]: {
...detail,
market_scan: payload.market_scan || undefined,
},
};
});
return payload.market_scan;
} catch {
return null;
}
};
useEffect(() => {
if (proAccess.loading) return;
if (!selectedCity) return;
@@ -826,6 +851,12 @@ export function DashboardStoreProvider({
if (selectedCityRef.current !== cityName) return;
if (detail.status === "fulfilled") {
setSelectedForecastDate(detail.value.local_date);
if (
proAccessRef.current.subscriptionActive &&
!detail.value.market_scan
) {
void ensureCityMarketScan(cityName, false);
}
}
})
.finally(() => {
@@ -834,6 +865,15 @@ export function DashboardStoreProvider({
});
};
useEffect(() => {
if (!selectedCity) return;
if (!proAccess.subscriptionActive) return;
const detail = cityDetailsByName[selectedCity];
if (!detail) return;
if (detail.market_scan) return;
void ensureCityMarketScan(selectedCity, false);
}, [cityDetailsByName, proAccess.subscriptionActive, selectedCity]);
const clearCityFocus = () => {
selectedCityRef.current = null;
setSelectedCity(null);