fixed weather code context

This commit is contained in:
ChrQR 2024-05-10 12:34:38 +02:00
parent 30518a0fba
commit 0a0481d63f
4 changed files with 5 additions and 7 deletions

View File

@ -26,7 +26,6 @@ export default function Home() {
<div className='block mx-auto max-w-4xl'> <div className='block mx-auto max-w-4xl'>
<LocationContext.Provider value={contextValue}> <LocationContext.Provider value={contextValue}>
<LocationSearch /> <LocationSearch />
<WeatherIcon />
<WeatherNow /> <WeatherNow />
</LocationContext.Provider> </LocationContext.Provider>
</div> </div>

View File

@ -9,5 +9,4 @@ export default function Temperature() {
return ( return (
<p>{feels}°C</p> <p>{feels}°C</p>
) )
} }

View File

@ -13,7 +13,6 @@ import sun from '../public/sun.svg'
import { useContext } from "react"; import { useContext } from "react";
import { WeatherContext } from "./WeatherNow"; import { WeatherContext } from "./WeatherNow";
import { HourlyForecast } from "@/types/types";
@ -83,11 +82,10 @@ function getCurrentWeatherIcon(weatherCode: number) {
export default function WeatherIcon() { export default function WeatherIcon() {
const { weather } = useContext(WeatherContext) const { weather } = useContext(WeatherContext)
const weatherCode = weather.current.weather_code
return( return(
<> <>
<Image src={getCurrentWeatherIcon(weatherCode)} alt="Weather icon"/> <Image src={getCurrentWeatherIcon(weather.current.weather_code)} alt="Weather icon"/>
{console.log(weatherCode)} {JSON.stringify(weather.current.weather_code)}
</> </>
) )
}; };

View File

@ -6,6 +6,7 @@ import { HourlyForecast, WeatherContextType} from "@/types/types";
import { createContext, useContext, useEffect, useState } from "react"; import { createContext, useContext, useEffect, useState } from "react";
import { defaultHourlyForecast } from "@/app/defaultState"; import { defaultHourlyForecast } from "@/app/defaultState";
import { LocationContext } from "@/app/page"; import { LocationContext } from "@/app/page";
import WeatherIcon from "./WeatherIcon";
export const WeatherContext = createContext<WeatherContextType>({ export const WeatherContext = createContext<WeatherContextType>({
weather: defaultHourlyForecast, weather: defaultHourlyForecast,
@ -35,6 +36,7 @@ export default function WeatherNow() {
<> <>
<h1>Here is the current weather in {geoLocation.name}</h1> <h1>Here is the current weather in {geoLocation.name}</h1>
<WeatherContext.Provider value={contextValue}> <WeatherContext.Provider value={contextValue}>
<WeatherIcon />
<Temperature /> <Temperature />
</WeatherContext.Provider> </WeatherContext.Provider>
</> </>