diff --git a/components/WeatherWidget.tsx b/components/WeatherWidget.tsx new file mode 100644 index 0000000..2901cbd --- /dev/null +++ b/components/WeatherWidget.tsx @@ -0,0 +1,27 @@ +import React, { useState, useEffect } from 'react'; + +const WeatherWidget = ({ location }) => { + const [weatherData, setWeatherData] = useState(null); + + useEffect(() => { + const fetchWeatherData = async () => { + // Fetch weather data for the specified location using an API + // Set the weather data in the state variable + }; + + fetchWeatherData(); + }, [location]); + + const formatWeatherData = (data) => { + // Format the weather data + // Return the formatted data + }; + + return ( +
+ {/* Render the formatted weather data */} +
+ ); +}; + +export default WeatherWidget; \ No newline at end of file diff --git a/components/WeatherWidgetContainer.tsx b/components/WeatherWidgetContainer.tsx new file mode 100644 index 0000000..49cb3f4 --- /dev/null +++ b/components/WeatherWidgetContainer.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import WeatherWidget from './WeatherWidget'; + +const WeatherWidgetContainer = () => { + const locations = ['London', 'Edinburgh', 'Alicante']; + + return ( +
+ {locations.map((location) => ( + + ))} +
+ ); +}; + +export default WeatherWidgetContainer; \ No newline at end of file diff --git a/components/utils/api.ts b/components/utils/api.ts new file mode 100644 index 0000000..f51f075 --- /dev/null +++ b/components/utils/api.ts @@ -0,0 +1,19 @@ +import axios from 'axios'; + +const BASE_URL = 'https://api.weatherapi.com/v1'; + +export const fetchWeatherData = async (location: string) => { + try { + const response = await axios.get(`${BASE_URL}/weather`, { + params: { + key: 'YOUR_API_KEY', + q: location, + }, + }); + + return response.data; + } catch (error) { + console.error('Error fetching weather data:', error); + throw error; + } +}; \ No newline at end of file diff --git a/components/utils/format.ts b/components/utils/format.ts new file mode 100644 index 0000000..a8c6707 --- /dev/null +++ b/components/utils/format.ts @@ -0,0 +1,13 @@ +export const formatWeatherData = (weatherData: any) => { + const temperature = weatherData.current.temp_c; + const humidity = weatherData.current.humidity; + const windSpeed = weatherData.current.wind_kph; + + const formattedWeatherData = { + temperature: `${temperature}°C`, + humidity: `${humidity}%`, + windSpeed: `${windSpeed} km/h`, + }; + + return formattedWeatherData; +}; \ No newline at end of file