aretherecookies-mobile/js/helpers/RouteHelpers.js

39 lines
993 B
JavaScript
Raw Normal View History

2017-04-16 11:43:27 -05:00
// @flow
2020-03-29 19:47:33 +00:00
import { curry, pipe, pathOr, path } from 'ramda';
import queryString from 'query-string';
2017-04-16 11:43:27 -05:00
2020-03-29 19:47:33 +00:00
const PARAM_BACK_TO = 'backto';
2017-04-16 11:56:58 -05:00
type RouteTo = {
pathname: string,
search?: string,
hash?: string,
state?: { [string]: string },
2017-04-16 11:56:58 -05:00
};
2017-04-16 11:43:27 -05:00
2018-08-12 11:34:45 -05:00
export const routeWithQuery = curry(
(pathname: string, queryParams?: { [string]: any }): RouteTo => {
return {
pathname,
search: queryString.stringify(queryParams),
};
}
);
2020-03-29 19:47:33 +00:00
export const routeWithTitle = curry((pathname: string, routeTitle: string): RouteTo =>
routeWithQuery(pathname, { routeTitle })
2018-08-05 10:38:47 -05:00
);
export const getSearch = pipe(
pathOr('', ['router', 'route', 'location', 'search']),
queryString.parse
);
2019-06-29 17:04:22 +00:00
2020-03-29 19:47:33 +00:00
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']);