feat: Implement initial PolyWeather dashboard with city list, detail view, map, and API endpoints.

This commit is contained in:
2569718930@qq.com
2026-03-06 09:05:40 +08:00
parent dc4167b514
commit af1d8ab4ed
10 changed files with 443 additions and 77 deletions
+15 -2
View File
@@ -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();
}