mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 07:44:54 -06:00
38 lines
993 B
JavaScript
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']);
|