handle err

This commit is contained in:
madarsbiss 2021-07-27 17:06:35 +03:00
parent 76595257e2
commit 924566489c

View File

@ -14,7 +14,7 @@ export default function Home() {
body: JSON.stringify({ input }), body: JSON.stringify({ input }),
}); });
const data = await res.json(); const data = await res.json();
// console.log(data); console.log(data);
setWeatherData({ ...data }); setWeatherData({ ...data });
setInput(""); setInput("");
@ -69,8 +69,7 @@ export default function Home() {
let hours = time.split(":")[0]; let hours = time.split(":")[0];
let minutes = time.split(":")[1]; let minutes = time.split(":")[1];
hours = hours % 12; hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12' hours = hours ? hours : 12;
// minutes = minutes < 10 ? "0" + minutes : minutes;
return hours + ":" + minutes; return hours + ":" + minutes;
}; };
@ -98,7 +97,7 @@ export default function Home() {
"Saturday", "Saturday",
]; ];
return weatherData ? ( return weatherData && !weatherData.message ? (
<div className={styles.wrapper}> <div className={styles.wrapper}>
<div className={styles.weatherWrapper}> <div className={styles.weatherWrapper}>
<h1 className={styles.locationTitle}> <h1 className={styles.locationTitle}>
@ -331,6 +330,17 @@ export default function Home() {
</div> </div>
</div> </div>
</div> </div>
) : weatherData && weatherData.message ? (
<>
<h1>City not found, try again</h1>
<input
type="text"
className={styles.searchInput}
onFocus={(e) => (e.target.value = "")}
onChange={(e) => setInput(e.target.value)}
onKeyDown={(e) => something(e)}
/>
</>
) : ( ) : (
<h1>Loading data...</h1> <h1>Loading data...</h1>
); );