code cleanup

This commit is contained in:
madarsbiss 2021-07-20 22:54:21 +03:00
parent cff9607214
commit 7deb989a10
3 changed files with 34 additions and 50 deletions

View File

@ -4,13 +4,14 @@ import Image from "next/image";
export default function Home() { export default function Home() {
const [input, setInput] = useState("mumbai"); const [input, setInput] = useState("mumbai");
const [systemUsed, setSystemUsed] = useState("metric");
const [weatherData, setWeatherData] = useState(); const [weatherData, setWeatherData] = useState();
const clickHandler = async () => { const clickHandler = async () => {
const res = await fetch("/api/data", { const res = await fetch("/api/data", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ input }), body: JSON.stringify({ input, systemUsed }),
}); });
const data = await res.json(); const data = await res.json();
console.log(data); console.log(data);
@ -55,6 +56,10 @@ export default function Home() {
return time; return time;
}; };
const changeSystem = () => {
console.log("system changed");
};
// console.log(convertTime(weatherData.dt, weatherData.timezone)); // console.log(convertTime(weatherData.dt, weatherData.timezone));
return ( return (
@ -64,6 +69,7 @@ export default function Home() {
<h1 className={styles.locationTitle}> <h1 className={styles.locationTitle}>
{weatherData.name}, {weatherData.sys.country} {weatherData.name}, {weatherData.sys.country}
</h1> </h1>
<p className={styles.weatherDescription}> <p className={styles.weatherDescription}>
{weatherData.weather[0].description} {weatherData.weather[0].description}
</p> </p>
@ -78,14 +84,15 @@ export default function Home() {
{Math.round(weatherData.main.temp)}° {Math.round(weatherData.main.temp)}°
</h1> </h1>
<p>Feels like {Math.round(weatherData.main.feels_like)}°</p> <p>Feels like {Math.round(weatherData.main.feels_like)}°</p>
{/* <h2>
{convertTime(weatherData.dt, weatherData.timezone)[0].split(":")[0]}
:00
</h2> */}
</div> </div>
)} )}
<div className={styles.statsWrapper}> <div className={styles.statsWrapper}>
<div className={styles.titleAndSearch}>
<h2 style={{ textAlign: "left" }}>
Today at:{" "}
{convertTime(weatherData.dt, weatherData.timezone)[0].split(":")[0]}
:00
</h2>
<input <input
type="text" type="text"
className={styles.searchInput} className={styles.searchInput}
@ -94,6 +101,8 @@ export default function Home() {
onChange={(e) => setInput(e.target.value)} onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => something(e)} onKeyDown={(e) => something(e)}
/> />
</div>
{weatherData && ( {weatherData && (
<div className={styles.statsBox}> <div className={styles.statsBox}>
<div className={styles.statsCard}> <div className={styles.statsCard}>
@ -155,24 +164,6 @@ export default function Home() {
</div> </div>
</div> </div>
</div> </div>
{/* <div className={styles.statsCard}>
Visibility: {weatherData.visibility / 1000} km
</div> */}
{/* <div className={styles.statsCard}>
<p>
Wind:{" "}
{` ${weatherData.wind.speed} ${degToCompass(
weatherData.wind.deg
)}`}
</p>
<Image
alt="weatherIcon"
src={`/icons/wind.png`}
height="100px"
width="100px"
/>
</div> */}
<div className={styles.statsCard}> <div className={styles.statsCard}>
<p>Sunrise</p> <p>Sunrise</p>
<div className={styles.statsCardContent}> <div className={styles.statsCardContent}>
@ -194,19 +185,6 @@ export default function Home() {
<p>AM</p> <p>AM</p>
</div> </div>
</div> </div>
{/* <p>
Sunrise:{" "}
{new Date(
weatherData.sys.sunrise * 1000 + weatherData.timezone * 1000
).toLocaleString("en-US")}
</p> */}
{/* <p>
Sunset:{" "}
{new Date(weatherData.sys.sunset * 1000).toLocaleString(
"en-US"
)}
</p> */}
</div> </div>
<div className={styles.statsCard}> <div className={styles.statsCard}>
<p>Sunset</p> <p>Sunset</p>

View File

@ -32,11 +32,16 @@
border-radius: 0 30px 30px 0; border-radius: 0 30px 30px 0;
} }
.titleAndSearch {
display: grid;
grid-template-columns: 2fr 1fr;
gap: 20px;
}
.statsBox { .statsBox {
display: grid; display: grid;
grid-template-columns: 1fr 1fr 1fr; grid-template-columns: 1fr 1fr 1fr;
gap: 20px; gap: 20px;
border-radius: 20px; border-radius: 20px;
} }
@ -58,13 +63,13 @@
.searchInput { .searchInput {
margin-bottom: 20px; margin-bottom: 20px;
height: 40px; height: 40px;
width: 200px; border: 2px solid rgb(34, 34, 34);
border: 2px solid rgb(230, 230, 230); /* border: none; */
padding: 0 10px; padding: 0 10px;
color: #c5c5c5; color: #303030;
font-size: 20px; font-size: 20px;
text-align: right; text-align: right;
border-radius: 20px; border-radius: 3px;
font-family: "Varela Round", sans-serif; font-family: "Varela Round", sans-serif;
font-size: 18px; font-size: 18px;
} }

View File

@ -17,6 +17,7 @@ body {
); );
font-family: "Varela Round", sans-serif; font-family: "Varela Round", sans-serif;
min-height: 100vh; min-height: 100vh;
padding-top: 50px;
} }
a { a {