diff --git a/package.json b/package.json index 1c0701a..81f8317 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@radix-ui/react-slot": "^1.0.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", + "date-fns": "^3.3.1", "lucide-react": "^0.312.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/src/components/main/Root.tsx b/src/components/main/Root.tsx index 144f9e7..34365df 100644 --- a/src/components/main/Root.tsx +++ b/src/components/main/Root.tsx @@ -1,9 +1,11 @@ import React, { useState, useEffect } from "react"; -import { LineChart, Line } from "recharts"; +import { LineChart, Line, CartesianGrid, XAxis, YAxis } from "recharts"; +import { format, addDays } from "date-fns"; -const onWeatherFetch = async function (cb) { +const fetchWeekForecastData = async function (dateTime, cb) { + const formattedDate = format(dateTime, "yyyy-MM-d"); const response = await fetch( - "http://api.weatherapi.com/v1/current.json?key=bfca7632f8dc4253859120435242301&q=Vienna&aqi=no", + `http://api.weatherapi.com/v1/future.json?key=bfca7632f8dc4253859120435242301&q=Vienna&dt=${formattedDate}`, ); const data = await response.json(); @@ -13,6 +15,9 @@ const onWeatherFetch = async function (cb) { const WeatherChart = function ({ data }) { + + + ; }; @@ -20,7 +25,7 @@ const App: React.FC = () => { const [data, setData] = useState(null); useEffect(() => { - onWeatherFetch(setData); + fetchWeekForecastData(addDays(new Date(), 14), setData); }, []); console.log(data); diff --git a/yarn.lock b/yarn.lock index ac505ad..e175ede 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1108,6 +1108,11 @@ d3-timer@^3.0.1: resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-3.0.1.tgz#6284d2a2708285b1abb7e201eda4380af35e63b0" integrity sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA== +date-fns@^3.3.1: + version "3.3.1" + resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-3.3.1.tgz#7581daca0892d139736697717a168afbb908cfed" + integrity sha512-y8e109LYGgoQDveiEBD3DYXKba1jWf5BA8YU1FL5Tvm0BTdEfy54WLCwnuYWZNnzzvALy/QQ4Hov+Q9RVRv+Zw== + debug@^4.1.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"