mirror of
https://github.com/10h30/fullstackopen.git
synced 2026-07-15 20:53:11 +09:00
Completed 2.14
This commit is contained in:
@@ -20,16 +20,16 @@ const App = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(ResultList)
|
console.log(ResultList)
|
||||||
if (ResultList.length > 0 ) {
|
if (ResultList.length === 1 ) {
|
||||||
const capital = ResultList[0].capital
|
const capital = ResultList[0].capital.replace(/\s/g, '+')
|
||||||
const apistring = `http://api.weatherstack.com/current?access_key=9482b8f61c984f8e1988759e020d133e&query=${capital}`
|
console.log(capital)
|
||||||
|
const apistring = `http://wttr.in/${capital}?format=j1`
|
||||||
console.log(capital, apistring)
|
console.log(capital, apistring)
|
||||||
axios
|
axios
|
||||||
.get(apistring)
|
.get(apistring)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
setWeatherdata(response.data)
|
setWeatherdata(response.data)
|
||||||
})
|
})
|
||||||
console.log(WeatherData)
|
|
||||||
}
|
}
|
||||||
}, [ResultList])
|
}, [ResultList])
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ const CountryLongList = ({data, onClick,weather}) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const CountryDetail = ({data,weather}) => {
|
const CountryDetail = ({data,weather}) => {
|
||||||
console.log(weather)
|
console.log("Data", data)
|
||||||
|
console.log("Length", data.length)
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h2>{data.name}</h2>
|
<h2>{data.name}</h2>
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
const Weather = ({weather,capital}) => {
|
const Weather = ({weather,capital}) => {
|
||||||
console.log(weather)
|
const {current_condition} = weather
|
||||||
|
const temperature = current_condition[0].temp_C
|
||||||
|
const windspeed = current_condition[0].windspeedKmph
|
||||||
|
const winddirection = current_condition[0].winddir16Point
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<p>Temperature: {weather.current.temperature} Celcius</p>
|
<h2>Weather in {capital}</h2>
|
||||||
<img src={weather.current.weather_icons} alt="Weather" />
|
{ weather &&
|
||||||
<p>Wind: {weather.current.wind_speed} mph {weather.current.wind_degree} {weather.current.wind_dir}</p>
|
<div>
|
||||||
|
<p>Temperature: {temperature} Celcius</p>
|
||||||
|
<p>Wind: {windspeed} km/h, Direction {winddirection}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user