feat: prioritize warnings for selected province
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
||||
WarningKind,
|
||||
} from "@/types/imgw";
|
||||
import { translate, type Language } from "@/lib/i18n";
|
||||
import { getProvinceFromTeryt, normalizeProvinceName } from "@/lib/provinces";
|
||||
|
||||
const locales: Record<Language, string> = { pl: "pl-PL", en: "en-GB" };
|
||||
|
||||
@@ -67,10 +68,14 @@ export function normalizeHydroStation(raw: RawHydroStation): HydroStation | null
|
||||
}
|
||||
|
||||
export function normalizeWarning(raw: RawWarning, kind: WarningKind, index: number): WeatherWarning {
|
||||
const provinces = [...new Set([
|
||||
...(raw.obszary ?? []).map((area) => normalizeProvinceName(area.wojewodztwo)),
|
||||
...(raw.teryt ?? []).map(getProvinceFromTeryt),
|
||||
].filter((province) => province !== null))];
|
||||
const describedAreas = (raw.obszary ?? [])
|
||||
.map((area) => area.opis?.trim() || area.wojewodztwo?.trim())
|
||||
.filter((area): area is string => Boolean(area));
|
||||
const areas = describedAreas.length ? describedAreas : (raw.teryt ?? []).map((code) => `TERYT ${code}`);
|
||||
const areas = describedAreas.length ? describedAreas : provinces;
|
||||
const title = raw.zdarzenie?.trim() || raw.nazwa_zdarzenia?.trim() || "";
|
||||
return {
|
||||
id: `${kind}-${raw.id ?? raw.numer ?? index}-${raw.data_od ?? raw.obowiazuje_od ?? "unknown"}`,
|
||||
@@ -84,6 +89,7 @@ export function normalizeWarning(raw: RawWarning, kind: WarningKind, index: numb
|
||||
publishedAt: normalizeDate(raw.opublikowano),
|
||||
probability: toNumber(raw.prawdopodobienstwo),
|
||||
areas,
|
||||
provinces,
|
||||
office: raw.biuro?.trim() || null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user