feat: prioritize meteorological warnings
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user