Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default function App() {
}
}, [cityKey])

async function getWeather(e) {
async function getCityKey(e) {
e.preventDefault()
const urlLocale = `http://dataservice.accuweather.com/locations/v1/cities/search`
const urlLocale = `https://dataservice.accuweather.com/locations/v1/cities/search`
const config = {
params: {
apikey: apiKey,
Expand All @@ -49,7 +49,7 @@ export default function App() {
}

function getWeatherNow() {
const urlWeather = `http://dataservice.accuweather.com/currentconditions/v1/${cityKey}`
const urlWeather = `https://dataservice.accuweather.com/currentconditions/v1/${cityKey}`
const config = {
params: {
apikey: apiKey,
Expand All @@ -58,11 +58,17 @@ export default function App() {
}
axios.get(urlWeather, config)
.then(res => setWeather(res.data[0]))
.catch(err => console.log(err))
.catch(err => {
if(err.status){
alert(err.data.Message)
} else {
alert('O número permitido de solicitações para a API foi excedido hoje. Tente novamente amanhã.\nThe allowed number of requests for the API has been exceeded today. Try again tomorrow.')
}
})
}

function getForecast() {
const urlForecast = `http://dataservice.accuweather.com/forecasts/v1/daily/5day/${cityKey}`
const urlForecast = `https://dataservice.accuweather.com/forecasts/v1/daily/5day/${cityKey}`
const config = {
params: {
apikey: apiKey,
Expand All @@ -72,7 +78,13 @@ export default function App() {
}
axios.get(urlForecast, config)
.then(res => setForecasts(res.data.DailyForecasts))
.catch(err => console.log(err))
.catch(err => {
if(err.status){
alert(err.data.Message)
} else {
alert('O número permitido de solicitações para a API foi excedido hoje. Tente novamente amanhã.\nThe allowed number of requests for the API has been exceeded today. Try again tomorrow.')
}
})
}


Expand All @@ -97,15 +109,15 @@ export default function App() {
<div className='App'>

<div className="city-form">
<form onSubmit={(e) => getWeather(e)}>
<form onSubmit={(e) => getCityKey(e)}>
<div className="form-group">
<input type="text"
className="form-control"
placeholder="Informe a cidade..."
onChange={e => setCity(e.target.value)} />
</div>
<button className="btn btn-primary" type="submit">
Clique para ver o tempo no sua cidade
Clique para ver o tempo na sua cidade
</button>
</form>
<div className="form-group ml-3">
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2070,9 +2070,9 @@ acorn-walk@^6.0.1:
integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA==

acorn@^5.5.3:
version "5.7.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279"
integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==
version "5.7.4"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e"
integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg==

acorn@^6.0.1, acorn@^6.0.4, acorn@^6.2.1:
version "6.4.0"
Expand Down