diff --git a/src/components/WeeklyForecast.tsx b/src/components/WeeklyForecast.tsx index db3589f..30072d2 100644 --- a/src/components/WeeklyForecast.tsx +++ b/src/components/WeeklyForecast.tsx @@ -1,13 +1,64 @@ -import React from 'react'; +import moment from 'moment'; +import React, { useCallback, useEffect, useState } from 'react'; +import { commonHttp } from '../utils/commonHttp'; +import { WeatherIcon } from './WeatherIcon'; +const url = + 'https://api.openweathermap.org/data/2.5/onecall?lat=-23.8041&lon=90.4152&exclude=current,alerts&units=metric&appid=895284fb2d2c50a520ea537456963d9c'; const WeeklyForecast: React.FC = () => { + const [data, setData] = useState(); + + const getData = useCallback(async () => { + const res = await commonHttp({ + method: 'get', + url: url, + }); + console.log('res.daily'); + console.log(res.daily); + setData(res?.daily); + }, []); + + useEffect(() => { + getData(); + return () => {}; + }, []); + return (

7-day forecast

+
+ {data?.length > 0 && + data?.map((el: any, i: number) => ( +
+
+
+ + {moment.unix(el?.dt).format('dddd')} + +
+
+ + {el?.weather?.length > 0 && ( + + )} + +
+
+

{el?.weather?.[0]?.main}

+
+
+

+ {el?.temp?.max}/{el?.temp?.min} +

+
+
+
+ ))} +
); }; - +//updated export default WeeklyForecast;