Skip to content

Instantly share code, notes, and snippets.

@dsingleton
Created August 2, 2017 15:12
Show Gist options
  • Save dsingleton/6790cc2556b09f31090e60ffe43dca0d to your computer and use it in GitHub Desktop.
Save dsingleton/6790cc2556b09f31090e60ffe43dca0d to your computer and use it in GitHub Desktop.
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