Skip to content

Commit

Permalink
feat(RmLanding): load countries from countries API
Browse files Browse the repository at this point in the history
add <select> tag to render all the countries
  • Loading branch information
aneurysmjs committed Jan 2, 2018
1 parent 3335154 commit d460425
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/constants/Urls.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default COUNTRIES = 'https://restcountries.eu/rest/v2';
export const COUNTRIES = 'https://restcountries.eu/rest/v2';
53 changes: 53 additions & 0 deletions src/containers/RmLanding/RmLanding.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
import React from 'react';
import { Link } from 'react-router-dom';

import { COUNTRIES } from '../../constants/Urls';
import api from 'api';

export default class RmLanding extends React.Component {

constructor() {
super();

this.state = {
selectedCountry: 'Colombia',
countries: []
};

this.handleChange = this.handleChange.bind(this);
}

/**
* @async
* @return {Promise<void>}
*/
async componentWillMount() {
try {
const { data } = await api.get(`${COUNTRIES}/all`);
this.setState({countries: data});
} catch (err) {
throw new Error('ReactMovies: ', err);
}
}

render () {
const { countries, selectedCountry } = this.state;

return (
<div className='RmLanding d-flex flex-column align-items-center justify-content-center'>
<h1>Movie Search</h1>
<form className="text-center col-md-4">
<div className="form-group">
<label htmlFor="countries">Select a Country</label>
<select
value={selectedCountry}
className="form-control"
onChange={this.handleChange}>
{countries.map(({ name }) => (
<option
id="countries"
key={name}
value={name}>
{name}
</option>
))}
</select>
</div>
</form>
<Link to="movies">
<button type="button" className="btn btn-primary">
See all movies
Expand All @@ -20,4 +63,14 @@ export default class RmLanding extends React.Component {
);
}

/**
*
* @param {SyntheticEvent} evt
* @return {void}
*/
handleChange(evt) {
const selectedCountry = evt.target.value;
this.setState({selectedCountry});
}

}

0 comments on commit d460425

Please sign in to comment.