From b7e0e0a24c3645d22f09803fa38df260b3ee30f3 Mon Sep 17 00:00:00 2001 From: madarsbiss Date: Wed, 21 Jul 2021 13:03:15 +0300 Subject: [PATCH] add flex center --- pages/index.js | 102 ++++++++++++++++++++++++++++++----------- styles/Home.module.css | 6 +-- styles/globals.css | 7 ++- 3 files changed, 84 insertions(+), 31 deletions(-) diff --git a/pages/index.js b/pages/index.js index 31111a7..a6ab545 100644 --- a/pages/index.js +++ b/pages/index.js @@ -14,7 +14,7 @@ export default function Home() { body: JSON.stringify({ input, systemUsed }), }); const data = await res.json(); - console.log(data); + setWeatherData({ ...data }); setInput(""); }; @@ -39,7 +39,7 @@ export default function Home() { "E", "ESE", "SE", - "SSE", + "S/SE", "S", "SSW", "SW", @@ -61,11 +61,28 @@ export default function Home() { }; const ctoF = (c) => (c * 9) / 5 + 32; - const mpsToMph = (mps) => (mps * 2.236936).toPrecision(3); - const kmToM = (km) => (km / 1.609).toPrecision(2); + const mpsToMph = (mps) => (mps * 2.236936).toFixed(2); + const kmToM = (km) => (km / 1.609).toFixed(1); + + const timeToAMPM = (time) => { + let hours = time.split(":")[0]; + let minutes = time.split(":")[1]; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + // minutes = minutes < 10 ? "0" + minutes : minutes; + return hours + ":" + minutes; + }; + + const isPM = (time) => { + let hours = time.split(":")[0]; + if (hours >= 12) { + return "PM"; + } else { + return "AM"; + } + }; const changeSystem = () => { - console.log("system changed"); if (systemUsed == "metric") { setSystemUsed("imperial"); } else { @@ -128,18 +145,23 @@ export default function Home() { ] } ,{" "} - { - convertTime(weatherData.dt, weatherData.timezone)[0].split( - ":" - )[0] - } - :00 + {systemUsed == "metric" + ? convertTime(weatherData.dt, weatherData.timezone)[0].split( + ":" + )[0] + : timeToAMPM( + convertTime(weatherData.dt, weatherData.timezone)[0] + ).split(":")[0]} + :00{" "} + {systemUsed == "imperial" + ? isPM(convertTime(weatherData.dt, weatherData.timezone)[0]) + : ""} )} (e.target.value = "")} onChange={(e) => setInput(e.target.value)} onKeyDown={(e) => something(e)} @@ -226,14 +248,28 @@ export default function Home() { />

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

-

AM

+

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

@@ -248,14 +284,28 @@ export default function Home() { />

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

-

PM

+

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

diff --git a/styles/Home.module.css b/styles/Home.module.css index 72788ae..1d7c6dc 100644 --- a/styles/Home.module.css +++ b/styles/Home.module.css @@ -1,6 +1,6 @@ .wrapper { max-width: 1200px; - margin: 0px auto; + /* margin: 0px auto; */ text-align: center; background: rgba(255, 255, 255, 0.95); box-shadow: 0 8px 32px 0 rgba(83, 89, 179, 0.37); @@ -63,8 +63,8 @@ .searchInput { margin-bottom: 20px; height: 40px; - border: 2px solid rgb(34, 34, 34); - /* border: none; */ + /* border: 2px solid rgb(34, 34, 34); */ + border: none; padding: 0 10px; color: #303030; font-size: 20px; diff --git a/styles/globals.css b/styles/globals.css index 5e95c53..de15f9b 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -16,8 +16,11 @@ body { rgba(245, 247, 252, 1) 100.2% ); font-family: "Varela Round", sans-serif; - min-height: 100vh; - padding-top: 50px; + height: 100vh; + width: 100vw; + display: flex; + justify-content: center; + align-items: center; } a {