feat: add global weather support
All checks were successful
CI / Lint, typecheck and build (push) Successful in 9m54s

This commit is contained in:
zv
2026-06-14 15:53:34 +02:00
parent d572c9cc53
commit 2182297adc
45 changed files with 739 additions and 212 deletions

View File

@@ -1,6 +1,7 @@
import type { Language } from "@/lib/i18n";
import type { Province } from "@/types/province";
import type { TemperatureUnit, WindSpeedUnit } from "@/types/units";
import type { WeatherRegion } from "@/types/weather-region";
interface VapidKeyResponse {
configured: boolean;
@@ -14,17 +15,20 @@ export async function fetchVapidPublicKey(signal?: AbortSignal) {
}
interface SavePushSubscriptionOptions {
region?: WeatherRegion;
officialWarningsEnabled?: boolean;
morningBriefEnabled?: boolean;
tomorrowBriefEnabled?: boolean;
latitude?: number | null;
longitude?: number | null;
locationName?: string | null;
timezone?: string | null;
countyTeryt?: string | null;
temperatureUnit?: TemperatureUnit;
windSpeedUnit?: WindSpeedUnit;
}
export async function savePushSubscription(subscription: PushSubscription, province: Province, language: Language, options: SavePushSubscriptionOptions = {}) {
export async function savePushSubscription(subscription: PushSubscription, province: Province | null, language: Language, options: SavePushSubscriptionOptions = {}) {
const response = await fetch("/api/notifications/subscriptions", {
method: "POST",
headers: { "content-type": "application/json" },
@@ -32,12 +36,14 @@ export async function savePushSubscription(subscription: PushSubscription, provi
subscription: subscription.toJSON(),
province,
language,
enabled: true,
region: options.region ?? "PL",
enabled: options.officialWarningsEnabled ?? true,
morningBriefEnabled: options.morningBriefEnabled === true,
tomorrowBriefEnabled: options.tomorrowBriefEnabled === true,
latitude: options.latitude ?? null,
longitude: options.longitude ?? null,
locationName: options.locationName ?? null,
timezone: options.timezone ?? null,
countyTeryt: options.countyTeryt ?? null,
temperatureUnit: options.temperatureUnit,
windSpeedUnit: options.windSpeedUnit,