From 5526c207eadd584fe275e7c7e9a9ce8a3b547015 Mon Sep 17 00:00:00 2001 From: Vance M Mcgrady <68658084+VanceMcGrady@users.noreply.github.com> Date: Wed, 17 Aug 2022 19:41:09 -0700 Subject: [PATCH] LocalWeather component refactored to receive location info from props --- client/components/LocalWeather.jsx | 60 ++++++------------------------ 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/client/components/LocalWeather.jsx b/client/components/LocalWeather.jsx index 1192f39..2ca4f46 100644 --- a/client/components/LocalWeather.jsx +++ b/client/components/LocalWeather.jsx @@ -1,4 +1,4 @@ -import axios from "axios"; + import React from "react"; import { FunnelChart } from "recharts"; @@ -7,55 +7,19 @@ import { FunnelChart } from "recharts"; const LocalWeather = props => { - - -const getWeather = () => { - - let api = "https://api.openweathermap.org/data/2.5/weather"; - let apiKey = "3865d44fbc4bfd45572787afb8fa06b2"; - - - navigator.geolocation.getCurrentPosition(success, error); - - function success(position){ - let latitude = position.coords.latitude; - let longitude = position.coords.longitude; - let url = `${api}?lat=${latitude}&lon=${longitude}&appid=${apiKey}&units=imperial`; - - fetch(url) - .then(res => res.json()) - .then(data => { - - - let location = document.getElementById("location") - let temperature = document.querySelector('#temperature'); - let description = document.querySelector('#description') - - let temp = data.main.temp; - temperature.innerHTML = temp + "° F"; - location.innerHTML = data.name; - description.innerHTML = data.weather[0].main; - - }) - console.log('position ', position); - console.log('latitude: ', latitude); - console.log('longitude: ', longitude); - - }; - - function error(){console.log('error finding location')} - - - -} - -getWeather() - return(