From 59bbcaea699c175a1661c24deb376f6c67410df3 Mon Sep 17 00:00:00 2001 From: ChrQR Date: Fri, 10 May 2024 01:00:26 +0200 Subject: [PATCH] Changed to open-meteo api and added location name to geoLocation state from places api --- app/actions.ts | 16 ++-- app/defaultState.ts | 14 ++- components/LocationSearch.tsx | 1 - components/WeatherNow.tsx | 23 +++-- types/types.ts | 166 +++++++++++++++++++++++----------- 5 files changed, 145 insertions(+), 75 deletions(-) diff --git a/app/actions.ts b/app/actions.ts index 568a6d5..50756c0 100644 --- a/app/actions.ts +++ b/app/actions.ts @@ -10,12 +10,15 @@ export async function getLocation(searchLocation: string): Promise{ throw new Error(`There was an error fetching the data`); } const data: LocationType = await res.json(); - return data.results[0].geometry.location; + return { + name: data.results[0].formatted_address, + geo: data.results[0].geometry.location + } } // takes coordinates in coordType format and returns json with weather forecast. export async function getForecast(geoLocation: coordType): Promise { - const { lat, lng } = geoLocation; + const { lat, lng } = geoLocation.geo; const appId = process.env.WEATHER_API; const res = await fetch( `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&appid=${appId}` @@ -28,11 +31,10 @@ export async function getForecast(geoLocation: coordType): Promise { } export async function getHourlyForecast(geoLocation: coordType): Promise { - const { lat, lng } = geoLocation; - const appId = process.env.WEATHER_API; - const res = await fetch( - `https://pro.openweathermap.org/data/2.5/forecast/hourly?lat=${lat}&lon=${lng}&appid=${appId}&mode=json&` - ); + const { lat, lng } = geoLocation.geo; + const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; + const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}¤t=temperature_2m,apparent_temperature,is_day,precipitation,rain,showers,snowfall,weather_code,cloud_cover,wind_speed_10m,wind_direction_10m&hourly=temperature_2m,apparent_temperature,precipitation_probability,precipitation,weather_code,wind_speed_10m,is_day&daily=weather_code,temperature_2m_max,temperature_2m_min,apparent_temperature_max,apparent_temperature_min,sunrise,sunset,daylight_duration,sunshine_duration,uv_index_max,precipitation_sum,precipitation_hours,wind_speed_10m_max&timezone=${tz}` + const res = await fetch(url); if (!res.ok) { throw new Error(`Failed to fetch the weather data`); } diff --git a/app/defaultState.ts b/app/defaultState.ts index 51c62ab..c7babb8 100644 --- a/app/defaultState.ts +++ b/app/defaultState.ts @@ -1,4 +1,4 @@ -import { coordType } from "@/types/types"; +import { HourlyForecast, coordType } from "@/types/types"; export const defaultState = { results: [ @@ -97,6 +97,12 @@ export const defaultForecast = { }; export const defaultGeoLocation: coordType = { - lat: 55.647229603577124, - lng: 12.54995987788925 -} \ No newline at end of file + name: 'copenhagen', + geo:{ + lat: 55.647229603577124, + lng: 12.54995987788925 + } +} + +export const defaultHourlyForecast: HourlyForecast = +{"latitude":52.52,"longitude":13.419998,"generationtime_ms":0.5199909210205078,"utc_offset_seconds":7200,"timezone":"Europe/Berlin","timezone_abbreviation":"CEST","elevation":38.0,"current_units":{"time":"iso8601","interval":"seconds","temperature_2m":"°C","apparent_temperature":"°C","is_day":"","precipitation":"mm","rain":"mm","showers":"mm","snowfall":"cm","weather_code":"wmo code","cloud_cover":"%","wind_speed_10m":"km/h","wind_direction_10m":"°"},"current":{"time":"2024-05-10T00:45","interval":900,"temperature_2m":12.8,"apparent_temperature":11.4,"is_day":0,"precipitation":0.00,"rain":0.00,"showers":0.00,"snowfall":0.00,"weather_code":3,"cloud_cover":100,"wind_speed_10m":3.2,"wind_direction_10m":63},"hourly_units":{"time":"iso8601","temperature_2m":"°C","apparent_temperature":"°C","precipitation_probability":"%","precipitation":"mm","weather_code":"wmo code","wind_speed_10m":"km/h","is_day":""},"hourly":{"time":["2024-05-10T00:00","2024-05-10T01:00","2024-05-10T02:00","2024-05-10T03:00","2024-05-10T04:00","2024-05-10T05:00","2024-05-10T06:00","2024-05-10T07:00","2024-05-10T08:00","2024-05-10T09:00","2024-05-10T10:00","2024-05-10T11:00","2024-05-10T12:00","2024-05-10T13:00","2024-05-10T14:00","2024-05-10T15:00","2024-05-10T16:00","2024-05-10T17:00","2024-05-10T18:00","2024-05-10T19:00","2024-05-10T20:00","2024-05-10T21:00","2024-05-10T22:00","2024-05-10T23:00","2024-05-11T00:00","2024-05-11T01:00","2024-05-11T02:00","2024-05-11T03:00","2024-05-11T04:00","2024-05-11T05:00","2024-05-11T06:00","2024-05-11T07:00","2024-05-11T08:00","2024-05-11T09:00","2024-05-11T10:00","2024-05-11T11:00","2024-05-11T12:00","2024-05-11T13:00","2024-05-11T14:00","2024-05-11T15:00","2024-05-11T16:00","2024-05-11T17:00","2024-05-11T18:00","2024-05-11T19:00","2024-05-11T20:00","2024-05-11T21:00","2024-05-11T22:00","2024-05-11T23:00","2024-05-12T00:00","2024-05-12T01:00","2024-05-12T02:00","2024-05-12T03:00","2024-05-12T04:00","2024-05-12T05:00","2024-05-12T06:00","2024-05-12T07:00","2024-05-12T08:00","2024-05-12T09:00","2024-05-12T10:00","2024-05-12T11:00","2024-05-12T12:00","2024-05-12T13:00","2024-05-12T14:00","2024-05-12T15:00","2024-05-12T16:00","2024-05-12T17:00","2024-05-12T18:00","2024-05-12T19:00","2024-05-12T20:00","2024-05-12T21:00","2024-05-12T22:00","2024-05-12T23:00","2024-05-13T00:00","2024-05-13T01:00","2024-05-13T02:00","2024-05-13T03:00","2024-05-13T04:00","2024-05-13T05:00","2024-05-13T06:00","2024-05-13T07:00","2024-05-13T08:00","2024-05-13T09:00","2024-05-13T10:00","2024-05-13T11:00","2024-05-13T12:00","2024-05-13T13:00","2024-05-13T14:00","2024-05-13T15:00","2024-05-13T16:00","2024-05-13T17:00","2024-05-13T18:00","2024-05-13T19:00","2024-05-13T20:00","2024-05-13T21:00","2024-05-13T22:00","2024-05-13T23:00","2024-05-14T00:00","2024-05-14T01:00","2024-05-14T02:00","2024-05-14T03:00","2024-05-14T04:00","2024-05-14T05:00","2024-05-14T06:00","2024-05-14T07:00","2024-05-14T08:00","2024-05-14T09:00","2024-05-14T10:00","2024-05-14T11:00","2024-05-14T12:00","2024-05-14T13:00","2024-05-14T14:00","2024-05-14T15:00","2024-05-14T16:00","2024-05-14T17:00","2024-05-14T18:00","2024-05-14T19:00","2024-05-14T20:00","2024-05-14T21:00","2024-05-14T22:00","2024-05-14T23:00","2024-05-15T00:00","2024-05-15T01:00","2024-05-15T02:00","2024-05-15T03:00","2024-05-15T04:00","2024-05-15T05:00","2024-05-15T06:00","2024-05-15T07:00","2024-05-15T08:00","2024-05-15T09:00","2024-05-15T10:00","2024-05-15T11:00","2024-05-15T12:00","2024-05-15T13:00","2024-05-15T14:00","2024-05-15T15:00","2024-05-15T16:00","2024-05-15T17:00","2024-05-15T18:00","2024-05-15T19:00","2024-05-15T20:00","2024-05-15T21:00","2024-05-15T22:00","2024-05-15T23:00","2024-05-16T00:00","2024-05-16T01:00","2024-05-16T02:00","2024-05-16T03:00","2024-05-16T04:00","2024-05-16T05:00","2024-05-16T06:00","2024-05-16T07:00","2024-05-16T08:00","2024-05-16T09:00","2024-05-16T10:00","2024-05-16T11:00","2024-05-16T12:00","2024-05-16T13:00","2024-05-16T14:00","2024-05-16T15:00","2024-05-16T16:00","2024-05-16T17:00","2024-05-16T18:00","2024-05-16T19:00","2024-05-16T20:00","2024-05-16T21:00","2024-05-16T22:00","2024-05-16T23:00"],"temperature_2m":[13.2,12.7,12.3,11.8,11.3,11.1,11.2,11.8,13.1,14.5,16.5,18.5,19.9,20.8,21.2,21.1,21.6,21.2,21.2,21.0,20.0,18.4,17.0,16.1,14.3,13.4,12.8,12.3,11.8,11.5,11.5,12.1,13.3,15.0,16.7,18.0,19.0,19.9,20.5,20.2,20.4,19.9,19.9,19.5,18.3,16.6,15.1,14.2,14.8,14.0,13.3,12.5,11.6,11.0,10.3,10.4,11.4,12.5,13.7,15.1,16.9,18.5,19.3,20.0,20.5,20.5,20.2,19.6,18.7,17.2,15.6,14.3,13.3,12.5,11.6,10.6,9.6,9.1,9.0,9.5,10.5,12.4,15.0,17.3,19.0,20.4,21.4,22.1,22.5,22.5,22.1,21.4,20.3,18.8,17.0,15.4,14.2,13.2,12.4,11.4,10.6,10.1,10.2,10.7,11.8,14.1,17.0,19.4,20.9,22.0,22.8,23.4,23.8,23.8,23.2,22.3,21.7,19.9,18.2,16.7,15.6,14.8,14.0,13.0,12.1,11.7,11.9,12.5,13.8,16.0,18.7,21.1,22.7,24.0,24.8,25.3,25.4,25.3,24.8,24.1,23.1,21.8,20.1,18.7,17.5,16.6,15.7,14.7,13.8,13.3,13.3,13.6,14.5,16.5,19.1,21.4,23.3,24.9,25.9,26.1,25.8,25.4,25.2,25.0,24.4,23.0,21.3,19.8],"apparent_temperature":[11.7,11.3,11.0,10.3,10.2,9.9,10.0,10.5,11.8,13.4,15.0,16.8,19.1,20.1,20.0,19.1,19.2,19.6,19.6,19.5,19.1,17.4,16.1,16.0,13.6,12.7,12.2,11.6,11.3,10.9,11.0,11.3,12.4,14.2,15.7,17.0,18.2,18.7,19.4,18.6,19.0,18.2,18.3,17.5,16.4,14.8,13.9,13.0,13.8,13.1,12.1,9.8,8.4,7.6,7.1,7.4,8.3,9.3,10.5,12.1,14.6,16.4,17.1,17.7,18.0,17.5,17.0,16.5,15.6,14.3,12.7,11.2,10.0,9.0,8.1,7.1,5.9,5.4,5.2,5.6,6.6,8.7,11.6,14.7,16.9,18.4,19.3,19.6,19.5,18.8,18.2,17.6,16.6,15.2,13.5,11.9,10.7,9.6,8.8,7.8,7.0,6.5,6.6,7.1,8.2,10.3,13.0,15.8,17.8,19.2,20.0,20.3,20.2,19.6,19.0,18.5,18.1,16.5,14.9,13.5,12.5,11.7,10.9,10.0,9.2,8.8,8.9,9.5,10.7,13.0,15.7,18.6,20.6,21.9,22.6,22.8,22.4,21.7,21.1,20.7,20.0,18.8,17.2,15.7,14.4,13.2,12.1,11.3,10.5,10.1,10.1,10.4,11.4,13.3,16.0,18.6,21.3,23.4,24.5,24.4,23.3,22.8,22.8,22.7,22.4,21.4,20.0,18.5],"precipitation_probability":[0,0,0,0,0,0,0,0,0,1,2,3,13,22,32,26,19,13,16,20,23,16,10,3,2,1,0,0,0,0,0,0,0,1,2,3,15,27,39,39,39,39,37,34,32,22,13,3,2,1,0,0,0,0,0,0,0,1,2,3,4,5,6,6,6,6,5,4,3,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,3,3,3,3,3,3,5,8,10,16,23,29,26,22,19,27,34,42,42,42,42,41,40,39,35,30,26,25,24,23,27,31,35,37,40,42,40,37,35,33,31,29,25,20,16,17,18,19,23,28,32,34,37,39,41,43,45,47,50,52,48,43,39,36,32,29],"precipitation":[0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.10,0.10,0.10],"weather_code":[3,3,3,3,3,3,3,2,3,3,2,2,1,2,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,3,2,3,3,3,2,3,2,2,3,2,2,3,2,2,2,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,3,3,3,3,3,3,2,2,2,1,1,1,3,3,3,3,3,3,3,3,3],"wind_speed_10m":[4.3,3.1,2.5,3.3,1.6,2.4,2.5,2.9,2.7,1.8,3.3,5.3,5.4,6.4,2.9,6.8,9.8,3.8,4.7,5.1,3.2,4.7,4.3,0.4,6.4,6.5,5.9,5.7,4.7,4.3,3.6,4.7,5.6,5.6,7.4,6.9,5.5,8.7,9.4,9.4,7.0,9.8,9.2,11.2,11.2,10.5,9.4,8.5,7.5,6.9,8.0,10.6,10.7,11.3,10.9,10.5,11.2,11.3,11.7,11.5,12.1,13.0,13.3,13.0,13.0,12.6,12.6,12.2,11.2,9.5,9.1,9.7,9.8,9.8,10.1,10.1,10.4,10.4,10.8,11.2,11.5,11.2,10.5,10.5,11.3,12.5,13.4,13.8,13.9,13.9,13.8,13.3,12.8,12.1,11.5,10.8,10.8,10.7,10.7,10.6,10.5,10.5,10.9,11.3,12.1,13.8,15.6,17.0,17.3,16.9,16.7,17.1,17.3,17.2,16.0,14.3,13.1,10.8,10.9,10.9,10.5,10.6,10.3,10.0,9.5,9.5,9.9,10.7,11.4,12.1,13.3,14.1,14.8,15.8,16.6,17.1,17.1,16.9,16.3,15.2,14.1,13.9,13.8,13.7,13.5,12.9,12.5,12.0,11.8,11.7,12.0,12.3,13.0,14.2,15.3,15.8,16.0,16.6,17.6,17.6,17.1,16.4,14.9,13.3,11.8,11.0,10.2,10.0],"is_day":[0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0]},"daily_units":{"time":"iso8601","weather_code":"wmo code","temperature_2m_max":"°C","temperature_2m_min":"°C","apparent_temperature_max":"°C","apparent_temperature_min":"°C","sunrise":"iso8601","sunset":"iso8601","daylight_duration":"s","sunshine_duration":"s","uv_index_max":"","precipitation_sum":"mm","precipitation_hours":"h","wind_speed_10m_max":"km/h"},"daily":{"time":["2024-05-10","2024-05-11","2024-05-12","2024-05-13","2024-05-14","2024-05-15","2024-05-16"],"weather_code":[3,3,3,0,0,1,3],"temperature_2m_max":[21.6,20.5,20.5,22.5,23.8,25.4,26.1],"temperature_2m_min":[11.1,11.5,10.3,9.0,10.1,11.7,13.3],"apparent_temperature_max":[20.1,19.4,18.0,19.6,20.3,22.8,24.5],"apparent_temperature_min":[9.9,10.9,7.1,5.2,6.5,8.8,10.1],"sunrise":["2024-05-10T05:17","2024-05-11T05:15","2024-05-12T05:13","2024-05-13T05:12","2024-05-14T05:10","2024-05-15T05:09","2024-05-16T05:07"],"sunset":["2024-05-10T20:48","2024-05-11T20:49","2024-05-12T20:51","2024-05-13T20:53","2024-05-14T20:54","2024-05-15T20:56","2024-05-16T20:57"],"daylight_duration":[55855.19,56051.30,56243.70,56433.89,56622.09,56808.11,56991.75],"sunshine_duration":[31010.11,35214.31,48237.02,51920.05,52104.48,52256.59,51818.46],"uv_index_max":[5.55,5.70,6.20,6.25,6.30,5.45,5.15],"precipitation_sum":[0.00,0.00,0.00,0.00,0.00,0.00,0.30],"precipitation_hours":[0.0,0.0,0.0,0.0,0.0,0.0,3.0],"wind_speed_10m_max":[9.8,11.2,13.3,13.9,17.3,17.1,17.6]}} \ No newline at end of file diff --git a/components/LocationSearch.tsx b/components/LocationSearch.tsx index ce4583d..c9c9f5a 100644 --- a/components/LocationSearch.tsx +++ b/components/LocationSearch.tsx @@ -3,7 +3,6 @@ import React, { useContext, useState } from "react"; import { getLocation } from "@/app/actions"; import { LocationContext } from "@/app/page"; - export default function LocationSearch() { const [searchLocation, setSearchLocation] = useState(""); const { geoLocation, setGeoLocation } = useContext(LocationContext); diff --git a/components/WeatherNow.tsx b/components/WeatherNow.tsx index fddf81a..c92589b 100644 --- a/components/WeatherNow.tsx +++ b/components/WeatherNow.tsx @@ -1,20 +1,28 @@ "use client"; -import { getForecast } from "@/app/actions"; +import { getForecast, getHourlyForecast } from "@/app/actions"; import Temperature from "./Temperature"; -import { Forecast, coordType } from "@/types/types"; -import { useContext, useEffect, useState } from "react"; -import { defaultForecast } from "@/app/defaultState"; +import { Forecast, HourlyForecast, WeatherContextType, coordType } from "@/types/types"; +import { createContext, useContext, useEffect, useState } from "react"; +import { defaultForecast, defaultHourlyForecast } from "@/app/defaultState"; import { LocationContext } from "@/app/page"; +export const weatherContext = createContext({ + weather: defaultHourlyForecast, + setWeather: () => {} // Default function, does nothing +}); export default function WeatherNow() { const { geoLocation } = useContext(LocationContext) - const [weather, setWeather] = useState(defaultForecast); + const [weather, setWeather] = useState(defaultHourlyForecast); + const contextValue: WeatherContextType = { + weather, + setWeather + }; useEffect(() => { let mounted = true; - getForecast(geoLocation).then((data) => { + getHourlyForecast(geoLocation).then((data) => { if (mounted) { setWeather(data); } @@ -25,8 +33,7 @@ export default function WeatherNow() { }, [geoLocation]); return ( <> -

Here is the current weather in {weather.name}

- +

Here is the current weather in {geoLocation.name}

); } diff --git a/types/types.ts b/types/types.ts index 0794920..09254aa 100644 --- a/types/types.ts +++ b/types/types.ts @@ -41,59 +41,107 @@ export interface Forecast { } export interface HourlyForecast { - cod: string; - message: number; - cnt: number; - list: Array<{ - dt: number; - main: { - temp: number; - feels_like: number; - temp_min: number; - temp_max: number; - pressure: number; - sea_level: number; - grnd_level: number; - humidity: number; - temp_kf: number; - }; - weather: Array<{ - id: number; - main: string; - description: string; - icon: string; - }>; - clouds: { - all: number; - }; - wind: { - speed: number; - deg: number; - gust: number; - }; - visibility: number; - pop: number; - rain?: { - "1h": number; - }; - sys: { - pod: string; - }; - dt_txt: string; - }>; - city: { - id: number; - name: string; - coord: { - lat: number; - lon: number; - }; - country: string; - population: number; - timezone: number; - sunrise: number; - sunset: number; - }; + latitude: number; + longitude: number; + generationtime_ms: number; + utc_offset_seconds: number; + timezone: string; + timezone_abbreviation: string; + elevation: number; + current_units: CurrentUnits; + current: CurrentWeather; + hourly_units: HourlyUnits; + hourly: HourlyWeather; + daily_units: DailyUnits; + daily: DailyWeather; +} + +interface CurrentUnits { + time: string; + interval: string; + temperature_2m: string; + apparent_temperature: string; + is_day: string; + precipitation: string; + rain: string; + showers: string; + snowfall: string; + weather_code: string; + cloud_cover: string; + wind_speed_10m: string; + wind_direction_10m: string; +} + +interface CurrentWeather { + time: string; + interval: number; + temperature_2m: number; + apparent_temperature: number; + is_day: number; + precipitation: number; + rain: number; + showers: number; + snowfall: number; + weather_code: number; + cloud_cover: number; + wind_speed_10m: number; + wind_direction_10m: number; +} + +interface HourlyUnits { + time: string; + temperature_2m: string; + apparent_temperature: string; + precipitation_probability: string; + precipitation: string; + weather_code: string; + wind_speed_10m: string; + is_day: string; +} + +interface HourlyWeather { + time: string[]; + temperature_2m: number[]; + apparent_temperature: number[]; + precipitation_probability: number[]; + precipitation: number[]; + weather_code: number[]; + wind_speed_10m: number[]; + is_day: number[]; +} + +interface DailyUnits { + time: string; + weather_code: string; + temperature_2m_max: string; + temperature_2m_min: string; + apparent_temperature_max: string; + apparent_temperature_min: string; + sunrise: string; + sunset: string; + daylight_duration: string; + sunshine_duration: string; + uv_index_max: string; + precipitation_sum: string; + precipitation_hours: string; + wind_speed_10m_max: string; +} + +interface DailyWeather { + time: string[]; + weather_code: number[]; + temperature_2m_max: number[]; + temperature_2m_min: number[]; + apparent_temperature_max: number[]; + apparent_temperature_min: number[]; + sunrise: string[]; + sunset: string[]; + daylight_duration: number[]; + sunshine_duration: number[]; + uv_index_max: number[]; + precipitation_sum: number[]; + precipitation_hours: number[]; + wind_speed_10m_max: number[]; } export interface LocationType { @@ -138,9 +186,12 @@ export interface LocationType { } export interface coordType { - lat: number; - lng: number; + name: string; + geo: { + lat: number; + lng: number;} } + export type EffectCallback = () => void | (() => void | undefined); export interface TempInfo { @@ -156,4 +207,9 @@ export interface TempInfo { export interface LocationContextType { geoLocation: coordType; setGeoLocation: React.Dispatch>; +} + +export interface WeatherContextType { + weather: HourlyForecast; + setWeather: React.Dispatch>; } \ No newline at end of file