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,15 +1,16 @@
"use client";
import { useQuery } from "@tanstack/react-query";
import { fetchImgwCurrentWeather } from "@/lib/imgw-current-api";
import { fetchCurrentWeather } from "@/lib/imgw-current-api";
import { QUERY_GC_TIME } from "@/lib/constants";
import type { WeatherRegion } from "@/types/weather-region";
const CURRENT_WEATHER_STALE_TIME = 2 * 60 * 1000;
export function useCurrentWeather(latitude?: number, longitude?: number) {
export function useCurrentWeather(latitude?: number, longitude?: number, region: WeatherRegion = "PL") {
return useQuery({
queryKey: ["imgw-current-weather", latitude, longitude],
queryFn: ({ signal }) => fetchImgwCurrentWeather(latitude as number, longitude as number, signal),
queryKey: ["current-weather", region, latitude, longitude],
queryFn: ({ signal }) => fetchCurrentWeather(latitude as number, longitude as number, region, signal),
staleTime: CURRENT_WEATHER_STALE_TIME,
gcTime: QUERY_GC_TIME,
retry: 1,

View File

@@ -3,11 +3,12 @@
import { useQuery } from "@tanstack/react-query";
import { fetchForecast } from "@/lib/forecast-api";
import { QUERY_GC_TIME } from "@/lib/constants";
import type { WeatherRegion } from "@/types/weather-region";
export function useForecast(latitude?: number, longitude?: number) {
export function useForecast(latitude?: number, longitude?: number, region: WeatherRegion = "PL") {
return useQuery({
queryKey: ["forecast", latitude, longitude],
queryFn: ({ signal }) => fetchForecast(latitude as number, longitude as number, signal),
queryKey: ["forecast", region, latitude, longitude],
queryFn: ({ signal }) => fetchForecast(latitude as number, longitude as number, region, signal),
enabled: Number.isFinite(latitude) && Number.isFinite(longitude),
staleTime: 15 * 60 * 1000,
gcTime: QUERY_GC_TIME,