Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default {
- search(maxDist) {
- const url = `${API_URL}&maxDistance=${maxDist}&minStars=${minStars}&maxResults=${maxRes}`;
- console.log(url);
- return fetch(url)
- .then(response => response.json())
- .then(result => {
- return result.items;
- });
- }
- };
- const MAX_DIST_CHANGED = "MAX_DIST_CHANGED";
- const initialState = {
- items: [],
- maxDist: "",
- minStars: "",
- maxRes: ""
- };
- export const actions = {
- maxDistChanged(maxDist) {
- return {
- type: MAX_DIST_CHANGED,
- maxDist
- };
- getItems(maxDist) {
- return {
- type: "ITEMS",
- payload: API.search(maxDist)
- };
- }
- };
- export function reducer(state = initialState, action) {
- switch (action.type) {
- case MAX_DIST_CHANGED: {
- return {
- ...state,
- maxDist: action.maxDist
- };
- }
- case "ITEMS_FULFILLED": {
- return {
- ...state,
- loading: false,
- items: action.payload
- };
- }
- default:
- return state;
- }
- }
- handleSubmit = e => {
- e.preventDefault();
- this.props.onGetItems(
- this.props.maxDist
- );
- };
- handleChange = event => this.props.onMaxDistChanged(event.target);
- function mapDisatchToProps(dispatch) {
- return {
- onMaxDistChanged(maxDist) {
- dispatch(actions.maxDistChanged(maxDist));
- }
- onGetItems(maxDist) {
- dispatch(actions.getItems(maxDist));
- }
- };
- }
Add Comment
Please, Sign In to add comment