@@ -17,6 +17,39 @@ const api = new WebMonitoringDb({
17
17
} ) ;
18
18
19
19
const localApi = new WebMonitoringApi ( api ) ;
20
+
21
+ // TODO: this messy page list stuff should really be turned into a context
22
+ // for more understandable code.
23
+ const withPages = ( ComponentType ) => {
24
+ const wrapper = ( { pages, loadPages, ...props } ) => {
25
+ useEffect ( ( ) => {
26
+ if ( ! pages ) {
27
+ loadPages ( ) ;
28
+ }
29
+ } ) ;
30
+
31
+ return < ComponentType
32
+ pages = { pages }
33
+ { ...props }
34
+ /> ;
35
+ } ;
36
+ wrapper . displayName = `${ ComponentType . displayName || ComponentType . name } WithPages` ;
37
+ return wrapper ;
38
+ } ;
39
+ // Dumb function wrapper since we have mostly class components and React
40
+ // Router now pretty much requires hooks.
41
+ const withUrlParams = ( ComponentType ) => {
42
+ const wrapper = ( props ) => {
43
+ const urlParams = useParams ( ) ;
44
+ const navigate = useNavigate ( ) ;
45
+ return < ComponentType navigate = { navigate } urlParams = { urlParams } { ...props } /> ;
46
+ } ;
47
+ wrapper . displayName = `${ ComponentType . displayName || ComponentType . name } WithUrlParams` ;
48
+ return wrapper ;
49
+ } ;
50
+ const PageListWithLoading = withUrlParams ( withPages ( PageList ) ) ;
51
+ const PageDetailsWithParams = withUrlParams ( PageDetails ) ;
52
+
20
53
/**
21
54
* WebMonitoringUi represents the root container for the app. It also maintains
22
55
* a top-level lsit of pages to share across the app. We do this here instead
@@ -136,38 +169,6 @@ export default class WebMonitoringUi extends Component {
136
169
return this . renderLoginDialog ( ) ;
137
170
}
138
171
139
- // TODO: this messy page list stuff should really be turned into a context
140
- // for more understandable code.
141
- const withPages = ( ComponentType ) => {
142
- const wrapper = ( { pages, ...props } ) => {
143
- useEffect ( ( ) => {
144
- if ( ! pages ) {
145
- this . loadPages ( ) ;
146
- }
147
- } ) ;
148
-
149
- return < ComponentType
150
- pages = { pages }
151
- { ...props }
152
- /> ;
153
- } ;
154
- wrapper . displayName = `${ ComponentType . displayName || ComponentType . name } WithPages` ;
155
- return wrapper ;
156
- } ;
157
- // Dumb function wrapper since we have mostly class components and React
158
- // Router now pretty much requires hooks.
159
- const withUrlParams = ( ComponentType ) => {
160
- const wrapper = ( props ) => {
161
- const urlParams = useParams ( ) ;
162
- const navigate = useNavigate ( ) ;
163
- return < ComponentType navigate = { navigate } urlParams = { urlParams } { ...props } /> ;
164
- } ;
165
- wrapper . displayName = `${ ComponentType . displayName || ComponentType . name } WithUrlParams` ;
166
- return wrapper ;
167
- } ;
168
- const PageListWithLoading = withUrlParams ( withPages ( PageList ) ) ;
169
- const PageDetailsWithParams = withUrlParams ( PageDetails ) ;
170
-
171
172
const modal = this . state . showLogin ? this . renderLoginDialog ( ) : null ;
172
173
173
174
return (
@@ -189,6 +190,7 @@ export default class WebMonitoringUi extends Component {
189
190
element = {
190
191
< PageListWithLoading
191
192
pages = { this . state . pages }
193
+ loadPages = { this . loadPages }
192
194
user = { this . state . user }
193
195
onSearch = { this . search }
194
196
/>
0 commit comments