diff --git a/app/layout.tsx b/app/layout.tsx index 3314e47..6740f09 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -5,8 +5,8 @@ import "./globals.css"; const inter = Inter({ subsets: ["latin"] }); export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "Get the weather anywhere!", + description: "Get todays weather hour-by-hour or a 7 day forecast!", }; export default function RootLayout({ diff --git a/app/page.tsx b/app/page.tsx index 0b541b0..a25ab6d 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -4,7 +4,6 @@ import WeatherNow from '../components/WeatherNow' import { createContext, useState } from 'react'; import { defaultGeoLocation } from './defaultState'; import { LocationContextType, coordType } from '@/types/types'; -import WeatherIcon from '@/components/WeatherIcon'; export const LocationContext = createContext({ @@ -22,8 +21,8 @@ export default function Home() { }; return ( -
-
+
+
diff --git a/components/HourlyCard.tsx b/components/HourlyCard.tsx deleted file mode 100644 index 5cccb66..0000000 --- a/components/HourlyCard.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { LocationContext } from "@/app/page" -import { useContext } from "react" - - - -export default function HourlyCard() { - const { geoLocation } = useContext(LocationContext) - return ( -

Hejsa

- ) -}; \ No newline at end of file diff --git a/components/HourlyCard/HourlyCard.tsx b/components/HourlyCard/HourlyCard.tsx new file mode 100644 index 0000000..3f86d2e --- /dev/null +++ b/components/HourlyCard/HourlyCard.tsx @@ -0,0 +1,14 @@ +import { HourlyCardPropType } from "@/types/types" +import WeatherIcon from "./WeatherIcon" +import HourlyTemp from "./HourlyTemp" + +export default function HourlyCard(props: HourlyCardPropType) { + const weatherCode = props.weather.weather_code[props.timeIndex] + const temperature = props.weather.apparent_temperature[props.timeIndex] + return ( + <> + + + + ) +}; \ No newline at end of file diff --git a/components/HourlyCard/HourlyTemp.tsx b/components/HourlyCard/HourlyTemp.tsx new file mode 100644 index 0000000..54d74d7 --- /dev/null +++ b/components/HourlyCard/HourlyTemp.tsx @@ -0,0 +1,7 @@ + +export default function HourlyTemp(props: {temperature: number;}) { + const feels = props.temperature; + return ( +

{feels}°C

+ ) +} \ No newline at end of file diff --git a/components/WeatherIcon.tsx b/components/HourlyCard/WeatherIcon.tsx similarity index 88% rename from components/WeatherIcon.tsx rename to components/HourlyCard/WeatherIcon.tsx index efd0fa3..f65f904 100644 --- a/components/WeatherIcon.tsx +++ b/components/HourlyCard/WeatherIcon.tsx @@ -11,8 +11,6 @@ import cloud from '../public/cloud.svg' import moon from '../public/moon.svg' import sun from '../public/sun.svg' -import { useContext } from "react"; -import { WeatherContext } from "./WeatherNow"; @@ -79,13 +77,12 @@ function getCurrentWeatherIcon(weatherCode: number) { } }; - -export default function WeatherIcon() { - const { weather } = useContext(WeatherContext) - return( +// this component takes WeatherIconPropType as props and shows the weather icon for the hour index it is given in timeIndex prop. +export default function WeatherIcon(props: {weatherCode: number}) { + const weatherCode = props.weatherCode + return ( <> - Weather icon - {JSON.stringify(weather.current.weather_code)} + Weather icon ) }; \ No newline at end of file diff --git a/components/LocationSearch.tsx b/components/LocationSearch.tsx index c9c9f5a..2703821 100644 --- a/components/LocationSearch.tsx +++ b/components/LocationSearch.tsx @@ -25,22 +25,18 @@ export default function LocationSearch() { }; return ( -
- - - -
+
+ +
); -} \ No newline at end of file +} diff --git a/components/WeatherHero.tsx b/components/WeatherHero.tsx new file mode 100644 index 0000000..eb03976 --- /dev/null +++ b/components/WeatherHero.tsx @@ -0,0 +1,91 @@ +import Image from "next/image"; +import cloudAndLightening from '../public/cloud-and-lightening.svg' +import cloudAndMoon from '../public/cloud-and-moon.svg' +import cloudAndRain from '../public/cloud-and-rain.svg' +import cloudAndSnow from '../public/cloud-and-snow.svg' +import cloudAndWind from '../public/cloud-and-wind.svg' +import cloudSnowRain from '../public/cloud-snow-rain.svg' +import cloudAndSun from '../public/cloud-and-sun.svg' +import cloudWindRain from '../public/cloud-wind-rain.svg' +import cloud from '../public/cloud.svg' +import moon from '../public/moon.svg' +import sun from '../public/sun.svg' + +import { useContext } from "react"; +import { WeatherContext } from "./WeatherNow"; + + + +function getCurrentWeatherIcon(weatherCode: number) { + switch (weatherCode) { + default: + return sun; + case 0: // clear sky + return sun; + case 1: // clear mainly + return cloudAndSun; + case 2: // partly cloudy + return cloud; + case 3: // overcast + return cloud; + case 45: // fog + return cloud; + case 48: // fog rime + return cloud; + case 51: // drizzle light + return cloudAndRain; + case 53: // drizzle moderate + return cloudAndRain; + case 55: // drizzle dense + return cloudAndRain; + case 56: // drizzle light freezing + return cloudSnowRain; + case 57: // drizzle dense freezing + return cloudSnowRain; + case 61: // rain slight + return cloudAndRain; + case 63: // rain moderate + return cloudAndRain; + case 65: // rain heavy + return cloudAndRain; + case 66: // rain light freezing + return cloudWindRain; + case 67: // rain dense freezing + return cloudWindRain; + case 71: // snow slight + return cloudAndSnow; + case 73: // snow moderate + return cloudAndSnow; + case 75: // snow heavy + return cloudAndSnow; + case 77: // snow grains + return cloudAndSnow; + case 80: // rain showers slight + return cloudAndRain; + case 81: // rain showers moderate + return cloudAndRain; + case 82: // rain showers violent + return cloudAndRain; + case 85: // snow showers slight + return cloudAndSnow; + case 86: // snow showers heavy + return cloudAndSnow; + case 95: // thunderstorm + return cloudAndLightening; + case 96: //thunderstorm hail slight + return cloudAndLightening; + case 99: //thunderstorm hail heavy + return cloudAndLightening; + } +}; + + +export default function WeatherHero() { + const { weather } = useContext(WeatherContext); + const weatherCode = weather.current.weather_code; + return( + <> + Weather icon + +) +}; \ No newline at end of file diff --git a/components/WeatherNow.tsx b/components/WeatherNow.tsx index c6eab4a..1cf907f 100644 --- a/components/WeatherNow.tsx +++ b/components/WeatherNow.tsx @@ -2,24 +2,23 @@ import { getHourlyForecast } from "@/app/actions"; import Temperature from "./Temperature"; -import { HourlyForecast, WeatherContextType} from "@/types/types"; +import { HourlyForecast, WeatherContextType } from "@/types/types"; import { createContext, useContext, useEffect, useState } from "react"; import { defaultHourlyForecast } from "@/app/defaultState"; import { LocationContext } from "@/app/page"; -import WeatherIcon from "./WeatherIcon"; +import WeatherHero from "./WeatherHero"; export const WeatherContext = createContext({ weather: defaultHourlyForecast, - setWeather: () => {} // Default function, does nothing + setWeather: () => {}, // Default function, does nothing }); - export default function WeatherNow() { - const { geoLocation } = useContext(LocationContext) + const { geoLocation } = useContext(LocationContext); const [weather, setWeather] = useState(defaultHourlyForecast); const contextValue: WeatherContextType = { weather, - setWeather + setWeather, }; useEffect(() => { let mounted = true; @@ -34,9 +33,11 @@ export default function WeatherNow() { }, [geoLocation]); return ( <> -

Here is the current weather in {geoLocation.name}

+

+ Here is the current weather in {geoLocation.name} +

- + diff --git a/types/types.ts b/types/types.ts index 09254aa..9ec074c 100644 --- a/types/types.ts +++ b/types/types.ts @@ -99,7 +99,7 @@ interface HourlyUnits { is_day: string; } -interface HourlyWeather { +export interface HourlyWeather { time: string[]; temperature_2m: number[]; apparent_temperature: number[]; @@ -212,4 +212,9 @@ export interface LocationContextType { export interface WeatherContextType { weather: HourlyForecast; setWeather: React.Dispatch>; +} + +export interface HourlyCardPropType { + weather: HourlyWeather; + timeIndex: number; } \ No newline at end of file