import { useState, useEffect } from "react"; import styles from "../styles/Home.module.css"; import Image from "next/image"; export default function Home() { const [input, setInput] = useState("mumbai"); const [systemUsed, setSystemUsed] = useState("metric"); const [weatherData, setWeatherData] = useState(); const clickHandler = async () => { const res = await fetch("/api/data", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ input, systemUsed }), }); const data = await res.json(); console.log(data); setWeatherData({ ...data }); setInput(""); }; const something = (event) => { if (event.keyCode === 13) { clickHandler(); } }; function degToCompass(num) { var val = Math.floor(num / 22.5 + 0.5); var arr = [ "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", ]; return arr[val % 16]; } const convertTime = (unixSeconds, timezone) => { const time = new Date((unixSeconds + timezone) * 1000) .toISOString() .match(/(\d{2}:\d{2})/); return time; }; const changeSystem = () => { console.log("system changed"); }; var weekday = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", ]; // console.log(convertTime(weatherData.dt, weatherData.timezone)); return (
{weatherData.weather[0].description}
Feels like {Math.round(weatherData.main.feels_like)}°
Humidity
%
Wind speed
m/s
Wind direction
Visibility
km
Sunrise
AM
Sunset
PM