feat: prioritize meteorological warnings

This commit is contained in:
zv
2026-06-02 20:56:33 +02:00
parent 5c150a193b
commit 99282c5280
3 changed files with 8 additions and 2 deletions

View File

@@ -56,6 +56,11 @@ async function fetchWarningsByKind(kind: WarningKind, signal?: AbortSignal): Pro
return Array.isArray(rows) ? rows.map((warning, index) => normalizeWarning(warning, kind, index)) : [];
}
function compareWarnings(a: WeatherWarning, b: WeatherWarning) {
if (a.kind !== b.kind) return a.kind === "meteo" ? -1 : 1;
return (b.publishedAt ?? "").localeCompare(a.publishedAt ?? "");
}
export async function fetchWarnings(signal?: AbortSignal): Promise<WeatherWarning[]> {
const results = await Promise.allSettled([
fetchWarningsByKind("meteo", signal),
@@ -65,5 +70,5 @@ export async function fetchWarnings(signal?: AbortSignal): Promise<WeatherWarnin
if (results.every((result) => result.status === "rejected")) {
throw new Error("Nie udało się pobrać ostrzeżeń IMGW.");
}
return warnings.sort((a, b) => (b.publishedAt ?? "").localeCompare(a.publishedAt ?? ""));
return warnings.sort(compareWarnings);
}