From a460d2e84010e59fa1ca3649f96b2987992b7133 Mon Sep 17 00:00:00 2001 From: zojgame Date: Tue, 30 Jul 2024 11:32:29 +0500 Subject: [PATCH] weather widget --- .../src/components/masterplanPage/map/Map.tsx | 2 + .../masterplanPage/map/WeatherWidget.tsx | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 client/src/components/masterplanPage/map/WeatherWidget.tsx diff --git a/client/src/components/masterplanPage/map/Map.tsx b/client/src/components/masterplanPage/map/Map.tsx index 785f1b6..3636a47 100644 --- a/client/src/components/masterplanPage/map/Map.tsx +++ b/client/src/components/masterplanPage/map/Map.tsx @@ -8,6 +8,7 @@ import ZoomControlls from "./ZoomControlls"; import { Clouds } from "./Clouds"; import { getWeather } from "../../../api/weather"; import { useEffect } from "react"; +import WeatherWidget from "./WeatherWidget"; const Map = () => { const { hoveredMarker } = useMarker(); @@ -40,6 +41,7 @@ const Map = () => { animationTime: 500, }} > + { + const [temperature, setTemperature] = useState(0); + + const date = new Date(); + + const day = date.toLocaleDateString("en-US", { + weekday: "short", + }); + const month = date.toLocaleDateString("en-US", { + month: "short", + }); + + const hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours(); + const minutes = String(date.getMinutes()).padStart(2, "0"); + const dayPart = `${date.getHours() >= 12 ? "PM" : "AM"}`; + const formattedTime = `${hours}:${minutes}`; + + useEffect(() => { + getWeather().then((data) => { + const temp = Math.round(data[0].main.temp); + setTemperature(temp); + }); + + return () => {}; + }, []); + + return ( +
+
+

{day}

+

{formattedTime}

+
+
+

+ {date.getDate()} {month} +

+

{dayPart}

+
+
+

{temperature}°C

+
+
+ ); +}; + +export default WeatherWidget;