Created
August 2, 2017 15:12
-
-
Save dsingleton/6790cc2556b09f31090e60ffe43dca0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function startRestaurantsSearch(shouldAutoLoadScheduled = true) { | |
return (dispatch, getState) => { | |
if (getState().restaurants.deliveryTime) { | |
return dispatch(loadScheduled()); | |
} | |
return dispatch(loadAsap()).then(() => { | |
if (shouldAutoLoadScheduled) { | |
return dispatch(loadScheduled()); | |
} | |
}); | |
}; | |
} | |
export function resumeRestaurantSearch() { | |
return (dispatch, getState) => { | |
const { nextBatch } = getState().restaurants; | |
if (nextBatch) { | |
return loadScheduled(); | |
} | |
}; | |
} | |
//----- | |
export function loadAsap() { | |
return (dispatch, getState) => { | |
const { restaurants, request } = getState(); | |
const params = { | |
...buildLocationParams(restaurants.location, request), | |
delivery_time: restaurants.deliveryTime, | |
page: !restaurants.deliveryTime ? restaurants.deliveryType : '', | |
}; | |
return dispatch({ | |
type: FETCH_RESTAURANTS_REPLACE, | |
endpoint: `/orderapp/v2/restaurants?${buildQueryParams(params)}`, | |
}); | |
}; | |
} | |
export function loadScheduled(isReplace) { | |
return (dispatch, getState) => { | |
// TODO: Rename nextbatch to scheduledUrl? | |
const { nextBatch } = getState().restaurants; | |
return dispatch({ | |
type: FETCH_RESTAURANTS_MERGE, | |
endpoint: `/${nextBatch.split('/').splice(3).join('/')}`, | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment