1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

65 lines
1.2 KiB
React
Raw Normal View History

2018-10-18 17:37:07 +02:00
/*
* Manage state
*/
2018-10-23 23:28:10 +02:00
import {filtersUrlEncode} from 'components/filters/encoding'
2018-10-18 18:25:40 +02:00
2018-10-23 23:28:10 +02:00
import {FILTER_GROUP_SOURCES,
FILTER_GROUP_ASNS,
FILTER_GROUP_COMMUNITIES,
FILTER_GROUP_EXT_COMMUNITIES,
FILTER_GROUP_LARGE_COMMUNITIES} from 'components/filters/groups'
2018-10-18 18:25:40 +02:00
2018-10-19 09:57:24 +02:00
/*
* Maybe this can be customized and injected into
2018-10-18 18:25:40 +02:00
* the PageLink component.
*/
export function makeLinkProps(props) {
const linkPage = parseInt(props.page, 10);
let pr = props.pageReceived;
let pf = props.pageFiltered;
// This here can be surely more elegant.
switch(props.anchor) {
case "received":
pr = linkPage;
break;
case "filtered":
pf = linkPage;
break;
}
2018-10-19 09:57:24 +02:00
let pagination = "";
if (pr) {
2018-12-16 17:22:54 +01:00
pagination += `pr=${pr}&`;
2018-10-19 09:57:24 +02:00
}
if (pf) {
2018-12-16 17:22:54 +01:00
pagination += `pf=${pf}&`;
2018-10-19 09:57:24 +02:00
}
2018-10-18 18:25:40 +02:00
let filtering = "";
if (props.filtersApplied) {
filtering = filtersUrlEncode(props.filtersApplied);
}
const query = props.routing.query.q || "";
2018-12-16 17:22:54 +01:00
const search = `?${pagination}q=${query}${filtering}`;
2018-10-23 23:28:10 +02:00
let hash = null;
2018-10-19 09:57:24 +02:00
if (props.anchor) {
2018-10-23 23:57:50 +02:00
hash = `#routes-${props.anchor}`;
2018-10-19 09:57:24 +02:00
}
2018-10-18 18:25:40 +02:00
const linkTo = {
pathname: props.routing.pathname,
hash: hash,
search: search,
};
return linkTo;
2018-10-18 17:37:07 +02:00
}