diff --git a/client/src/api/urls.ts b/client/src/api/urls.ts index ddb8774..09939a2 100644 --- a/client/src/api/urls.ts +++ b/client/src/api/urls.ts @@ -1,6 +1,10 @@ // const serverApi = "http://192.168.56.1:3000"; const serverApi = "http://194.26.138.94:4002"; // const serverApi = import.meta.env.VITE_SERVER_API; +const city = "Dubai"; +const contry = "UAE"; +const weatherApiKey = "908ad75f36452c11ff4306cd53162218"; +const weatherApi = `https://api.openweathermap.org/data/2.5/forecast?q=${city},${contry}&units=metric&appid=${weatherApiKey}`; const apartmentsApi = `${serverApi}/apartments`; @@ -8,4 +12,4 @@ const currentApartmentApi = `${serverApi}/apartment`; const updateAccessTokenApi = `${serverApi}/updateAccessToken`; -export { apartmentsApi, updateAccessTokenApi, currentApartmentApi }; +export { apartmentsApi, updateAccessTokenApi, currentApartmentApi, weatherApi }; diff --git a/client/src/api/weather.ts b/client/src/api/weather.ts new file mode 100644 index 0000000..c1b196d --- /dev/null +++ b/client/src/api/weather.ts @@ -0,0 +1,72 @@ +import { weatherApi } from "./urls"; + +/** + * + * + */ + +type WeatherRes = { + cod: string; + message: number; + cnt: number; + list: { + dt: number; + main: { + temp: number; + feels_like: number; + temp_min: number; + temp_max: number; + pressure: number; + sea_level: number; + grnd_level: number; + humidity: number; + temp_kf: number; + }; + weather: { + id: number; + main: string; + description: string; + icon: string; + }[]; + clouds: { + all: number; + }; + wind: { + speed: number; + deg: number; + gust: number; + }; + visibility: number; + pop: number; + sys: { + pod: string; + }; + dt_txt: string; + }[]; + city: { + id: number; + name: string; + coord: { + lat: number; + lon: number; + }; + country: string; + population: number; + timezone: number; + sunrise: number; + sunset: number; + }; +}; + +async function getWeather() { + const response = await fetch(weatherApi); + const fetchedData: WeatherRes = await response.json(); + + const listByDay = fetchedData.list.filter((day) => + day.dt_txt.endsWith("15:00:00") + ); + + return listByDay; +} + +export { getWeather }; diff --git a/client/src/components/masterplanPage/map/Clouds.tsx b/client/src/components/masterplanPage/map/Clouds.tsx index d4984e9..6328571 100644 --- a/client/src/components/masterplanPage/map/Clouds.tsx +++ b/client/src/components/masterplanPage/map/Clouds.tsx @@ -11,14 +11,14 @@ function Clouds() { return (
{
const { hoveredMarker } = useMarker();
@@ -18,6 +21,12 @@ const Map = () => {
};
});
+ useEffect(() => {
+ getWeather().then((data) => {
+ console.log(data);
+ });
+ }, []);
+
return (
{day}
+{formattedTime}
++ {date.getDate()} {month} +
+{dayPart}
+{temperature}°C
+