feat: Implement initial PolyWeather dashboard with city list, detail view, map, and API endpoints.
This commit is contained in:
+15
-2
@@ -1,9 +1,20 @@
|
||||
import type { CityDetail, CitySummary } from "@/lib/types";
|
||||
|
||||
async function readError(res: Response, fallback: string) {
|
||||
try {
|
||||
const data = await res.json();
|
||||
const msg = data?.error ? String(data.error) : fallback;
|
||||
const detail = data?.detail ? ` ${String(data.detail)}` : "";
|
||||
return `${msg}${detail}`.trim();
|
||||
} catch {
|
||||
return `${fallback}: ${res.status}`;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCities(): Promise<CitySummary[]> {
|
||||
const res = await fetch("/api/cities", { cache: "no-store" });
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to load cities: ${res.status}`);
|
||||
throw new Error(await readError(res, `Failed to load cities (${res.status})`));
|
||||
}
|
||||
const data = await res.json();
|
||||
return data.cities ?? [];
|
||||
@@ -21,7 +32,9 @@ export async function getCityDetail(
|
||||
},
|
||||
);
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to load city detail: ${res.status}`);
|
||||
throw new Error(
|
||||
await readError(res, `Failed to load city detail (${res.status})`),
|
||||
);
|
||||
}
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
export type Locale = "zh" | "en";
|
||||
|
||||
export const copy = {
|
||||
en: {
|
||||
brandSubtitle: "Global Weather Risk Intelligence",
|
||||
technicalGuide: "Technical Guide",
|
||||
monitoredCities: "Monitored Cities",
|
||||
cityDetail: "City Detail",
|
||||
selectCityHint: "Select a city from the left list or map marker.",
|
||||
live: "Live",
|
||||
cities: "Cities",
|
||||
currentMax: "Current / Max",
|
||||
cloud: "Cloud",
|
||||
wind: "Wind",
|
||||
topProb: "Top Settlement Probabilities",
|
||||
noProb: "No probability data yet.",
|
||||
aiSummary: "AI Summary",
|
||||
noAnalysis: "No analysis yet.",
|
||||
refresh: "Refresh",
|
||||
fahrenheit: "Fahrenheit",
|
||||
celsius: "Celsius",
|
||||
high: "High",
|
||||
medium: "Med",
|
||||
low: "Low",
|
||||
loadCitiesFailed: "Failed to load cities",
|
||||
loadCityDetailFailed: "Failed to load city detail",
|
||||
backendConfigMissing:
|
||||
"Server config missing: POLYWEATHER_API_BASE_URL is not set.",
|
||||
},
|
||||
zh: {
|
||||
brandSubtitle: "全球天气风险智能分析",
|
||||
technicalGuide: "技术说明",
|
||||
monitoredCities: "监控城市",
|
||||
cityDetail: "城市详情",
|
||||
selectCityHint: "请从左侧列表或地图标记选择城市。",
|
||||
live: "实时",
|
||||
cities: "城市",
|
||||
currentMax: "当前 / 最高",
|
||||
cloud: "云量",
|
||||
wind: "风速",
|
||||
topProb: "结算概率Top3",
|
||||
noProb: "暂无概率数据",
|
||||
aiSummary: "AI 分析",
|
||||
noAnalysis: "暂无分析",
|
||||
refresh: "刷新",
|
||||
fahrenheit: "华氏",
|
||||
celsius: "摄氏",
|
||||
high: "高",
|
||||
medium: "中",
|
||||
low: "低",
|
||||
loadCitiesFailed: "城市列表加载失败",
|
||||
loadCityDetailFailed: "城市详情加载失败",
|
||||
backendConfigMissing: "服务端未配置 POLYWEATHER_API_BASE_URL。",
|
||||
},
|
||||
} as const;
|
||||
Reference in New Issue
Block a user