Add JMA Haneda temps and fix stale detail loading
This commit is contained in:
@@ -961,6 +961,10 @@
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.root :global(.forecast-inline-note) {
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.root :global(.forecast-day) {
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1px solid var(--border-subtle);
|
||||
@@ -1000,6 +1004,31 @@
|
||||
color: var(--accent-cyan);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.root :global(.forecast-table) {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
overflow-x: auto;
|
||||
padding-bottom: 4px;
|
||||
scroll-snap-type: x proximity;
|
||||
}
|
||||
|
||||
.root :global(.forecast-table::-webkit-scrollbar) {
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
.root :global(.forecast-table::-webkit-scrollbar-thumb) {
|
||||
background: rgba(148, 163, 184, 0.32);
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.root :global(.forecast-day) {
|
||||
flex: 0 0 112px;
|
||||
min-width: 112px;
|
||||
scroll-snap-align: start;
|
||||
}
|
||||
}
|
||||
|
||||
.root :global(.sun-info) {
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
|
||||
@@ -724,6 +724,7 @@ export function ForecastTable() {
|
||||
if (!data) return null;
|
||||
|
||||
const daily = data.forecast?.daily || [];
|
||||
const isSparseDaily = daily.length <= 1;
|
||||
const resolveForecastTemp = (date: string, fallback: number | null | undefined) => {
|
||||
const debPrediction = data.multi_model_daily?.[date]?.deb?.prediction;
|
||||
return debPrediction ?? fallback ?? null;
|
||||
@@ -731,6 +732,20 @@ export function ForecastTable() {
|
||||
return (
|
||||
<section className="forecast-section">
|
||||
<h3>{t("forecast.title")}</h3>
|
||||
{isSparseDaily && (
|
||||
<div
|
||||
className="forecast-inline-note"
|
||||
style={{
|
||||
color: "var(--text-secondary)",
|
||||
fontSize: "12px",
|
||||
marginBottom: "10px",
|
||||
}}
|
||||
>
|
||||
{store.loadingState.cityDetail
|
||||
? "多日预报同步中,正在刷新完整日序列。"
|
||||
: "当前只收到当日预报,其他日期结果暂未回传。"}
|
||||
</div>
|
||||
)}
|
||||
<div className="forecast-table">
|
||||
{daily.length === 0 ? (
|
||||
<EmptyState text={t("forecast.empty")} />
|
||||
|
||||
@@ -77,7 +77,8 @@ function DashboardScreen() {
|
||||
// Avoid full-page flashing on initial load; only show this overlay for manual refresh.
|
||||
const showLoading =
|
||||
store.loadingState.cities ||
|
||||
store.loadingState.refresh;
|
||||
store.loadingState.refresh ||
|
||||
store.loadingState.cityDetail;
|
||||
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
|
||||
@@ -106,6 +106,11 @@ function countAvailableModels(
|
||||
).length;
|
||||
}
|
||||
|
||||
function countForecastDays(detail?: CityDetail | null): number {
|
||||
const daily = detail?.forecast?.daily;
|
||||
return Array.isArray(daily) ? daily.length : 0;
|
||||
}
|
||||
|
||||
function hasSparseModelCoverage(
|
||||
detail?: CityDetail | null,
|
||||
targetDate?: string | null,
|
||||
@@ -113,6 +118,16 @@ function hasSparseModelCoverage(
|
||||
return countAvailableModels(detail, targetDate) <= 1;
|
||||
}
|
||||
|
||||
function hasSparseDetailCoverage(
|
||||
detail?: CityDetail | null,
|
||||
targetDate?: string | null,
|
||||
): boolean {
|
||||
if (!detail) return true;
|
||||
return (
|
||||
hasSparseModelCoverage(detail, targetDate) || countForecastDays(detail) <= 1
|
||||
);
|
||||
}
|
||||
|
||||
export function DashboardStoreProvider({
|
||||
children,
|
||||
}: {
|
||||
@@ -244,7 +259,13 @@ export function DashboardStoreProvider({
|
||||
const ensureCityDetail = async (cityName: string, force = false) => {
|
||||
const cached = cityDetailsByName[cityName];
|
||||
const cachedMeta = cityDetailMetaByName[cityName];
|
||||
if (!force && cached && dashboardClient.isCityDetailFresh(cachedMeta)) {
|
||||
const cachedIsSparse = hasSparseDetailCoverage(cached, cached?.local_date);
|
||||
if (
|
||||
!force &&
|
||||
cached &&
|
||||
!cachedIsSparse &&
|
||||
dashboardClient.isCityDetailFresh(cachedMeta)
|
||||
) {
|
||||
scheduleBackgroundDetailRefresh(cityName, cached, cachedMeta);
|
||||
return cached;
|
||||
}
|
||||
@@ -254,6 +275,28 @@ export function DashboardStoreProvider({
|
||||
const summary = await dashboardClient.getCitySummary(cityName);
|
||||
const revision = getCityRevision(summary);
|
||||
if (revision && revision === cachedMeta?.revision) {
|
||||
if (cachedIsSparse) {
|
||||
const latestDetail = await dashboardClient.getCityDetail(cityName, {
|
||||
force: true,
|
||||
});
|
||||
const detail = latestDetail;
|
||||
setCityDetailsByName((current) => ({
|
||||
...current,
|
||||
[cityName]: detail,
|
||||
}));
|
||||
setCitySummariesByName((current) => ({
|
||||
...current,
|
||||
[cityName]: toCitySummary(detail),
|
||||
}));
|
||||
setCityDetailMetaByName((current) => ({
|
||||
...current,
|
||||
[cityName]: {
|
||||
cachedAt: Date.now(),
|
||||
revision: getCityRevision(detail),
|
||||
},
|
||||
}));
|
||||
return detail;
|
||||
}
|
||||
setCityDetailMetaByName((current) => ({
|
||||
...current,
|
||||
[cityName]: {
|
||||
@@ -472,9 +515,14 @@ export function DashboardStoreProvider({
|
||||
await refreshProAccess();
|
||||
}
|
||||
const access = proAccessRef.current;
|
||||
const cachedDetail = cityDetailsByName[cityName];
|
||||
const needsDetailRefresh = hasSparseDetailCoverage(
|
||||
cachedDetail,
|
||||
cachedDetail?.local_date,
|
||||
);
|
||||
setLoadingState((current) => ({ ...current, cityDetail: true }));
|
||||
try {
|
||||
const detail = await ensureCityDetail(cityName);
|
||||
const detail = await ensureCityDetail(cityName, needsDetailRefresh);
|
||||
setSelectedForecastDate(detail.local_date);
|
||||
if (access.authenticated && access.subscriptionActive) {
|
||||
// 预热市场数据,不做 await 阻塞,后台静默拉取
|
||||
@@ -621,9 +669,9 @@ export function DashboardStoreProvider({
|
||||
setFutureModalDate(dateStr);
|
||||
if (!selectedCity || !proAccess.subscriptionActive) return;
|
||||
const cachedDetail = cityDetailsByName[selectedCity];
|
||||
const needsModelRefresh =
|
||||
!forceRefresh && hasSparseModelCoverage(cachedDetail, dateStr);
|
||||
if (needsModelRefresh) {
|
||||
const needsDetailRefresh =
|
||||
!forceRefresh && hasSparseDetailCoverage(cachedDetail, dateStr);
|
||||
if (needsDetailRefresh) {
|
||||
void ensureCityDetail(selectedCity, true).catch(() => {});
|
||||
}
|
||||
const cacheKey = getMarketScanCacheKey(selectedCity, dateStr);
|
||||
@@ -652,8 +700,9 @@ export function DashboardStoreProvider({
|
||||
setFutureModalDate(cachedDetail.local_date);
|
||||
}
|
||||
if (!proAccess.subscriptionActive) return;
|
||||
const needsModelRefresh =
|
||||
!forceRefresh && hasSparseModelCoverage(cachedDetail, cachedDetail?.local_date);
|
||||
const needsDetailRefresh =
|
||||
!forceRefresh &&
|
||||
hasSparseDetailCoverage(cachedDetail, cachedDetail?.local_date);
|
||||
|
||||
setLoadingState((current) => ({
|
||||
...current,
|
||||
@@ -664,7 +713,7 @@ export function DashboardStoreProvider({
|
||||
try {
|
||||
const detail = await ensureCityDetail(
|
||||
selectedCity,
|
||||
Boolean(forceRefresh || needsModelRefresh),
|
||||
Boolean(forceRefresh || needsDetailRefresh),
|
||||
);
|
||||
setSelectedForecastDate(detail.local_date);
|
||||
setFutureModalDate(detail.local_date);
|
||||
|
||||
@@ -342,9 +342,18 @@ export function useLeafletMap({
|
||||
}).addTo(map);
|
||||
|
||||
marker.on("click", () => {
|
||||
map.stop();
|
||||
// Reset lastMovedCity so we can re-fly if needed
|
||||
lastMovedCityRef.current = null;
|
||||
const currentMap = mapRef.current;
|
||||
currentMap?.stop();
|
||||
if (currentMap && !suspendMotion) {
|
||||
currentMap.flyTo([city.lat, city.lon], 11, {
|
||||
animate: true,
|
||||
duration: 1.05,
|
||||
easeLinearity: 0.22,
|
||||
});
|
||||
lastMovedCityRef.current = city.name;
|
||||
} else {
|
||||
lastMovedCityRef.current = null;
|
||||
}
|
||||
onSelectCityRef.current(city.name);
|
||||
});
|
||||
|
||||
|
||||
@@ -57,6 +57,12 @@ export function getCityRevision(source?: CityDetail | CitySummary | null) {
|
||||
? source.multi_model_daily?.[source.local_date || ""]
|
||||
: null;
|
||||
const modelFootprint = modelDaily?.models || ("multi_model" in source ? source.multi_model : null);
|
||||
const forecastFootprint =
|
||||
"forecast" in source && Array.isArray(source.forecast?.daily)
|
||||
? source.forecast.daily
|
||||
.map((item) => `${normalizeRevisionPart(item?.date)}:${normalizeRevisionPart(item?.max_temp)}`)
|
||||
.join("|")
|
||||
: "";
|
||||
return [
|
||||
normalizeRevisionPart(source.updated_at),
|
||||
normalizeRevisionPart(source.current?.obs_time),
|
||||
@@ -70,6 +76,7 @@ export function getCityRevision(source?: CityDetail | CitySummary | null) {
|
||||
.join("|")
|
||||
: "",
|
||||
),
|
||||
normalizeRevisionPart(forecastFootprint),
|
||||
].join("|");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user