-
Notifications
You must be signed in to change notification settings - Fork 3
/
usePageInfo.ts
47 lines (41 loc) · 1.12 KB
/
usePageInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { useHistory, useLocation } from "react-router-dom";
import { stringify } from "qs";
import { pick } from "lodash";
import { getPageInfo } from "../utils/helper";
const usePageInfo = () => {
const { search } = useLocation();
const history = useHistory();
const pageInfo = getPageInfo(search);
const setSort = (sort: string) => {
if (sort === "") {
history.replace({
search: stringify({
...pick(pageInfo, [
"page",
"size",
"retired",
"tokenName",
"query",
"minPoolSize",
"maxPoolSize",
"minPledge",
"maxPledge",
"minSaturation",
"maxSaturation",
"minBlockLifetime",
"maxBlockLifetime",
"minVotingPower",
"maxVotingPower",
"minGovParticipationRate",
"maxGovParticipationRate"
]),
page: 1
})
});
} else {
history.replace({ search: stringify({ ...pageInfo, page: 1, sort }) });
}
};
return { pageInfo, setSort };
};
export default usePageInfo;