fix initial load

This commit is contained in:
madarsbiss 2021-07-24 06:41:47 +03:00
parent 471e12da16
commit 548e68ab0f
2 changed files with 197 additions and 193 deletions

View File

@ -6,6 +6,7 @@ export default function Home() {
const [input, setInput] = useState("mumbai"); const [input, setInput] = useState("mumbai");
const [systemUsed, setSystemUsed] = useState("metric"); const [systemUsed, setSystemUsed] = useState("metric");
const [weatherData, setWeatherData] = useState(); const [weatherData, setWeatherData] = useState();
// const [isLoading, setIsLoading] = useState(true);
const getData = async () => { const getData = async () => {
const res = await fetch("/api/data", { const res = await fetch("/api/data", {
@ -100,9 +101,8 @@ export default function Home() {
"Saturday", "Saturday",
]; ];
return ( return weatherData ? (
<div className={styles.wrapper}> <div className={styles.wrapper}>
{weatherData && (
<div className={styles.weatherWrapper}> <div className={styles.weatherWrapper}>
<h1 className={styles.locationTitle}> <h1 className={styles.locationTitle}>
{weatherData.name}, {weatherData.sys.country} {weatherData.name}, {weatherData.sys.country}
@ -132,10 +132,9 @@ export default function Home() {
°{systemUsed == "metric" ? "C" : "F"} °{systemUsed == "metric" ? "C" : "F"}
</p> </p>
</div> </div>
)}
<div className={styles.statsWrapper}> <div className={styles.statsWrapper}>
<div className={styles.titleAndSearch}> <div className={styles.titleAndSearch}>
{weatherData && (
<h2 style={{ textAlign: "left" }}> <h2 style={{ textAlign: "left" }}>
{ {
weekday[ weekday[
@ -157,7 +156,7 @@ export default function Home() {
? isPM(convertTime(weatherData.dt, weatherData.timezone)[0]) ? isPM(convertTime(weatherData.dt, weatherData.timezone)[0])
: ""} : ""}
</h2> </h2>
)}
<input <input
type="text" type="text"
className={styles.searchInput} className={styles.searchInput}
@ -168,7 +167,6 @@ export default function Home() {
/> />
</div> </div>
{weatherData && (
<div className={styles.statsBox}> <div className={styles.statsBox}>
<div className={styles.statsCard}> <div className={styles.statsCard}>
<p>Humidity</p> <p>Humidity</p>
@ -310,10 +308,12 @@ export default function Home() {
</div> </div>
</div> </div>
</div> </div>
)}
<p onClick={changeSystem}>Metric System</p> <p onClick={changeSystem}>Metric System</p>
<p onClick={changeSystem}>Imperial System</p> <p onClick={changeSystem}>Imperial System</p>
</div> </div>
</div> </div>
) : (
<h1>Loading results</h1>
); );
} }

View File

@ -11,6 +11,10 @@
margin: 0 20px; margin: 0 20px;
} }
.wrapperHide {
display: none;
}
.weatherWrapper { .weatherWrapper {
padding: 30px; padding: 30px;
} }