aretherecookies-mobile/js/helpers/RouteHelpers.js
2020-03-29 19:47:33 +00:00

38 lines
993 B
JavaScript

// @flow
import { curry, pipe, pathOr, path } from 'ramda';
import queryString from 'query-string';
const PARAM_BACK_TO = 'backto';
type RouteTo = {
pathname: string,
search?: string,
hash?: string,
state?: { [string]: string },
};
export const routeWithQuery = curry(
(pathname: string, queryParams?: { [string]: any }): RouteTo => {
return {
pathname,
search: queryString.stringify(queryParams),
};
}
);
export const routeWithTitle = curry((pathname: string, routeTitle: string): RouteTo =>
routeWithQuery(pathname, { routeTitle })
);
export const getSearch = pipe(
pathOr('', ['router', 'route', 'location', 'search']),
queryString.parse
);
export const getViewMode = pipe(getSearch, pathOr('list', ['viewMode']));
export const getBackTo = pipe(getSearch, path([PARAM_BACK_TO]));
export const loginWithBackto = (backto: string) => `/login?${PARAM_BACK_TO}=${backto}`;
export const getPathname = pathOr('/list/food', ['router', 'route', 'location', 'pathname']);