-
Notifications
You must be signed in to change notification settings - Fork 795
/
admin.js
137 lines (121 loc) · 3.93 KB
/
admin.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* External dependencies
*/
import ReactDOM from 'react-dom';
import React from 'react';
import { Provider } from 'react-redux';
import { Route, Router, useRouterHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import { createHashHistory } from 'history';
import { assign, get } from 'lodash';
/**
* Internal dependencies
*/
import accessibleFocus from 'lib/accessible-focus';
import store from 'state/redux-store';
import i18n from 'i18n-calypso';
import Main from 'main';
import * as actionTypes from 'state/action-types';
// Initialize the accessibile focus to allow styling specifically for keyboard navigation
accessibleFocus();
const Initial_State = window.Initial_State;
Initial_State.locale = JSON.parse( Initial_State.locale );
Initial_State.locale = get( Initial_State.locale, [ 'locale_data', 'jetpack' ], {} );
if ( 'undefined' !== typeof Initial_State.locale[ '' ] ) {
Initial_State.locale[ '' ].localeSlug = Initial_State.localeSlug;
// Overloading the toLocaleString method to use the set locale
Number.prototype.realToLocaleString = Number.prototype.toLocaleString;
Number.prototype.toLocaleString = function( locale, options ) {
locale = locale || Initial_State.localeSlug;
options = options || {};
return this.realToLocaleString( locale, options );
};
} else {
Initial_State.locale = { '': { localeSlug: Initial_State.localeSlug } };
}
i18n.setLocale( Initial_State.locale );
const hashHistory = useRouterHistory( createHashHistory )();
const history = syncHistoryWithStore( hashHistory, store );
// Add dispatch and actionTypes to the window object so we can use it from the browser's console
if ( 'undefined' !== typeof window && process.env.NODE_ENV === 'development' ) {
assign( window, {
actionTypes: actionTypes,
dispatch: store.dispatch,
} );
}
render();
function render() {
const container = document.getElementById( 'jp-plugin-container' );
if ( container === null ) {
return;
}
ReactDOM.render(
<div>
<Provider store={ store }>
<Router history={ history }>
<Route
path="/"
name={ i18n.translate( 'At A Glance', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route path="/dashboard" name={ i18n.translate( 'At A Glance' ) } component={ Main } />
<Route
path="/my-plan"
name={ i18n.translate( 'My Plan', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/plans"
name={ i18n.translate( 'Plans', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/plans-prompt"
name={ i18n.translate( 'Plans', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/settings"
name={ i18n.translate( 'Settings', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/discussion"
name={ i18n.translate( 'Discussion', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/security"
name={ i18n.translate( 'Security', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/performance"
name={ i18n.translate( 'Performance', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/traffic"
name={ i18n.translate( 'Traffic', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/writing"
name={ i18n.translate( 'Writing', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route
path="/sharing"
name={ i18n.translate( 'Sharing', { context: 'Navigation item.' } ) }
component={ Main }
/>
<Route path="/wpbody-content" component={ Main } />
<Route path="/wp-toolbar" component={ Main } />
<Route path="/privacy" component={ Main } />
<Route path="*" component={ Main } />
</Router>
</Provider>
</div>,
container
);
}