UNPKG

2.07 kBJavaScriptView Raw
1import { METHODS } from './router';
2
3export const SET_PAGE = 'PLATFORM__SET_PAGE';
4export const SET_STATUS = 'PLATFORM__SET_STATUS';
5export const GOTO_PAGE_INDEX = 'PLATFORM__GOTO_PAGE_INDEX';
6export const NAVIGATE_TO_URL = 'PLATFORM__NAVIGATE_TO_URL';
7export const SET_SHELL = 'PLATFORM__SET_SHELL';
8export const REDIRECT = 'PLATFORM__REDIRECT';
9export const REROUTE_PAGE = 'PLATFORM__REROUTE_PAGE'; // re-run the handlers for the page
10
11export const setPage = (url, { urlParams={}, queryParams={}, hashParams={}, referrer='' }={}) => ({
12 type: SET_PAGE,
13 payload: { url, urlParams, queryParams, hashParams, referrer },
14});
15
16export const gotoPageIndex = (
17 pageIndex,
18 pathName,
19 {
20 queryParams={},
21 hashParams={},
22 referrer='',
23 }={}
24) => ({
25 type: GOTO_PAGE_INDEX,
26 payload: { pageIndex, pathName, queryParams, hashParams, referrer },
27});
28
29export const navigateToUrl = (
30 method,
31 pathName,
32 {
33 queryParams={},
34 hashParams={},
35 bodyParams={},
36 referrer='',
37 }={}
38) => ({
39 type: NAVIGATE_TO_URL,
40 payload: { method, pathName, queryParams, hashParams, bodyParams, referrer },
41});
42
43export const setShell = shell => ({ type: SET_SHELL, shell });
44
45export const redirect = url => ({ type: REDIRECT, url });
46
47export const reroutePage = () => async (dispatch, getState) => {
48 const { currentPage } = getState().platform;
49
50 dispatch(navigateToUrl(
51 METHODS.GET,
52 currentPage.url,
53 {
54 queryParams: currentPage.queryParams,
55 hashParams: currentPage.hashParams,
56 bodyParams: {},
57 referrer: currentPage.referrer,
58 }
59 ));
60};
61
62export const activateClient = () => async (dispatch, getState) => {
63 const { platform } = getState();
64 if (!platform.shell) { return; }
65
66 dispatch(setShell(false));
67 dispatch(reroutePage());
68};
69
70export const setStatus = status => ({
71 type: SET_STATUS,
72 payload: { status },
73});
74
75export default {
76 SET_PAGE,
77 SET_STATUS,
78 GOTO_PAGE_INDEX,
79 NAVIGATE_TO_URL,
80 SET_SHELL,
81 REROUTE_PAGE,
82 setPage,
83 setStatus,
84 gotoPageIndex,
85 navigateToUrl,
86 setShell,
87 reroutePage,
88};