feat: implement city weather detail API routing, dashboard data models, and monitoring infrastructure

This commit is contained in:
2569718930@qq.com
2026-05-14 14:21:28 +08:00
parent 0e220d890f
commit 02add6d994
18 changed files with 990 additions and 58 deletions
+29 -3
View File
@@ -74,6 +74,10 @@ interface DashboardStoreValue extends DashboardState {
}
const DashboardStoreContext = createContext<DashboardStoreValue | null>(null);
const DashboardActionsContext = createContext<Pick<
DashboardStoreValue,
"ensureCityDetail"
> | null>(null);
const CityDetailsContext = createContext<{
cityDetailsByName: Record<string, CityDetail>;
cityDetailMetaByName: Record<string, { cachedAt: number; revision: string }>;
@@ -1550,12 +1554,24 @@ export function DashboardStoreProvider({
() => ({ cityDetailsByName, cityDetailMetaByName, citySummariesByName, loadingState }),
[cityDetailsByName, cityDetailMetaByName, citySummariesByName, loadingState],
);
const latestEnsureCityDetailRef = useRef(ensureCityDetail);
useEffect(() => {
latestEnsureCityDetailRef.current = ensureCityDetail;
}, [ensureCityDetail]);
const dashboardActionsValue = useMemo<Pick<DashboardStoreValue, "ensureCityDetail">>(
() => ({
ensureCityDetail: (...args) => latestEnsureCityDetailRef.current(...args),
}),
[],
);
return (
<DashboardStoreContext.Provider value={value}>
<CityDetailsContext.Provider value={cityDetailsValue}>
{children}
</CityDetailsContext.Provider>
<DashboardActionsContext.Provider value={dashboardActionsValue}>
<CityDetailsContext.Provider value={cityDetailsValue}>
{children}
</CityDetailsContext.Provider>
</DashboardActionsContext.Provider>
</DashboardStoreContext.Provider>
);
}
@@ -1580,6 +1596,16 @@ export function useCityDetails() {
return context;
}
export function useDashboardActions() {
const context = useContext(DashboardActionsContext);
if (!context) {
throw new Error(
"useDashboardActions must be used within DashboardStoreProvider",
);
}
return context;
}
export function useCityData(name?: string | null) {
const store = useDashboardStore();
const key = name || store.selectedCity;