diff --git a/pages/components/MetricCard.jsx b/pages/components/MetricCard.jsx new file mode 100644 index 0000000..2bb3b09 --- /dev/null +++ b/pages/components/MetricCard.jsx @@ -0,0 +1,19 @@ +import React from "react"; +import Image from "next/image"; + +const MetricCard = ({ title, iconSrc, metric, unit = "", styles }) => { + return ( +
+

{title}

+
+ weatherIcon +
+

{metric}

+

{unit}

+
+
+
+ ); +}; + +export default MetricCard; diff --git a/pages/index.js b/pages/index.js index 91bd43a..fbf708e 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,6 +1,7 @@ import { useState, useEffect } from "react"; import styles from "../styles/Home.module.css"; import Image from "next/image"; +import MetricCard from "./components/MetricCard"; export default function Home() { const [input, setInput] = useState("Riga"); @@ -172,152 +173,90 @@ export default function Home() {
-
-

Humidity

-
- weatherIcon -
-

{weatherData.main.humidity}

-

%

-
-
-
-
-

Wind speed

-
- weatherIcon -
-

- {systemUsed == "metric" - ? weatherData.wind.speed - : mpsToMph(weatherData.wind.speed)} -

-

{systemUsed == "metric" ? "m/s" : "m/h"}

-
-
-
-
-

Wind direction

-
- weatherIcon -
-

{degToCompass(weatherData.wind.deg)}

-
-
-
-
-

Visibility

-
- weatherIcon -
-

- {systemUsed == "metric" - ? (weatherData.visibility / 1000).toPrecision(2) - : kmToM(weatherData.visibility / 1000)} -

-

{systemUsed == "metric" ? "km" : "miles"}

-
-
-
-
-

Sunrise

-
- weatherIcon -
-

- {systemUsed == "metric" - ? `${parseInt( - convertTime( - weatherData.sys.sunrise, - weatherData.timezone - )[0].split(":")[0] - )}:${ - convertTime( - weatherData.sys.sunrise, - weatherData.timezone - )[0].split(":")[1] - }` - : timeToAMPM( - convertTime( - weatherData.sys.sunrise, - weatherData.timezone - )[0] - )} -

-

- {systemUsed == "imperial" - ? isPM( - convertTime( - weatherData.sys.sunrise, - weatherData.timezone - )[0] - ) - : ""} -

-
-
-
-
-

Sunset

-
- weatherIcon -
-

- {systemUsed == "metric" - ? convertTime( - weatherData.sys.sunset, - weatherData.timezone - )[0] - : timeToAMPM( - convertTime( - weatherData.sys.sunset, - weatherData.timezone - )[0] - )} -

-

- {systemUsed == "imperial" - ? isPM( - convertTime( - weatherData.sys.sunset, - weatherData.timezone - )[0] - ) - : ""} -

-
-
-
+ + + + + + + + + + +