@@ -3,13 +3,14 @@ import PropTypes from 'prop-types';
3
3
import nullable from 'prop-types-nullable' ;
4
4
import {
5
5
BrowserRouter as Router ,
6
- Switch ,
6
+ Routes ,
7
7
Route ,
8
8
Link ,
9
9
Redirect ,
10
10
useHistory ,
11
11
useLocation ,
12
- useRouteMatch ,
12
+ useMatch ,
13
+ useNavigate ,
13
14
} from 'react-router-dom' ;
14
15
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
15
16
import Collapse from '@kunukn/react-collapse' ;
@@ -147,10 +148,15 @@ function PureApp({
147
148
} , [ ] ) ;
148
149
149
150
// TODO: move stuff that depends on this to the App.
150
- const history = useHistory ( ) ;
151
+ const navigate = useNavigate ( ) ;
152
+ React . useEffect ( ( ) => {
153
+ selfoss . navigate = navigate ;
154
+ } , [ navigate ] ) ;
155
+
156
+ const entriesPageMatch = useMatch ( ENTRIES_ROUTE_PATTERN ) ;
151
157
React . useEffect ( ( ) => {
152
- selfoss . history = history ;
153
- } , [ history ] ) ;
158
+ selfoss . entriesPageMatch = entriesPageMatch ;
159
+ } , [ entriesPageMatch ] ) ;
154
160
155
161
// Prepare path of the homepage for redirecting from /
156
162
let homePagePath = configuration . homepage . split ( '/' ) ;
@@ -181,97 +187,113 @@ function PureApp({
181
187
< React . StrictMode >
182
188
< Message message = { globalMessage } />
183
189
184
- < Switch >
185
- < Route path = "/sign/in" >
186
- { /* menu open for smartphone */ }
187
- < div id = "loginform" role = "main" >
188
- < LoginForm
189
- { ...{ offlineEnabled} }
190
- />
191
- </ div >
192
- </ Route >
193
-
194
- < Route path = "/" >
195
- < CheckAuthorization
196
- isAllowed = { selfoss . isAllowedToRead ( ) }
197
- _ = { _ }
198
- >
199
- < div id = "nav-mobile" role = "navigation" >
200
- < div id = "nav-mobile-logo" >
201
- < div id = "nav-mobile-count" className = { classNames ( { 'unread-count' : true , offline : offlineState , online : ! offlineState , unread : unreadItemsCount > 0 } ) } >
202
- < span className = { classNames ( { 'offline-count' : true , offline : offlineState , online : ! offlineState , diff : unreadItemsCount !== unreadItemsOfflineCount && unreadItemsOfflineCount } ) } > { unreadItemsOfflineCount > 0 ? unreadItemsOfflineCount : '' } </ span >
203
- < span className = "count" > { unreadItemsCount } </ span >
190
+ < Routes >
191
+ < Route
192
+ path = "/sign/in"
193
+ element = {
194
+ /* menu open for smartphone */
195
+ < div id = "loginform" role = "main" >
196
+ < LoginForm
197
+ { ...{ offlineEnabled} }
198
+ />
199
+ </ div >
200
+ }
201
+ />
202
+
203
+ < Route
204
+ path = "/"
205
+ element = {
206
+ < CheckAuthorization
207
+ isAllowed = { selfoss . isAllowedToRead ( ) }
208
+ _ = { _ }
209
+ >
210
+ < div id = "nav-mobile" role = "navigation" >
211
+ < div id = "nav-mobile-logo" >
212
+ < div id = "nav-mobile-count" className = { classNames ( { 'unread-count' : true , offline : offlineState , online : ! offlineState , unread : unreadItemsCount > 0 } ) } >
213
+ < span className = { classNames ( { 'offline-count' : true , offline : offlineState , online : ! offlineState , diff : unreadItemsCount !== unreadItemsOfflineCount && unreadItemsOfflineCount } ) } > { unreadItemsOfflineCount > 0 ? unreadItemsOfflineCount : '' } </ span >
214
+ < span className = "count" > { unreadItemsCount } </ span >
215
+ </ div >
204
216
</ div >
217
+ < button
218
+ id = "nav-mobile-settings"
219
+ accessKey = "t"
220
+ aria-label = { _ ( 'settingsbutton' ) }
221
+ onClick = { menuButtonOnClick }
222
+ >
223
+ < FontAwesomeIcon icon = { icons . menu } size = "2x" />
224
+ </ button >
205
225
</ div >
206
- < button
207
- id = "nav-mobile-settings"
208
- accessKey = "t"
209
- aria-label = { _ ( 'settingsbutton' ) }
210
- onClick = { menuButtonOnClick }
211
- >
212
- < FontAwesomeIcon icon = { icons . menu } size = "2x" />
213
- </ button >
214
- </ div >
215
226
216
- { /* navigation */ }
217
- < Collapse isOpen = { ! smartphone || navExpanded } className = "collapse-css-transition" >
218
- < div id = "nav" role = "navigation" >
219
- < Navigation
220
- entriesPage = { entriesPage }
221
- setNavExpanded = { setNavExpanded }
222
- navSourcesExpanded = { navSourcesExpanded }
223
- setNavSourcesExpanded = { setNavSourcesExpanded }
224
- offlineState = { offlineState }
225
- allItemsCount = { allItemsCount }
226
- allItemsOfflineCount = { allItemsOfflineCount }
227
- unreadItemsCount = { unreadItemsCount }
228
- unreadItemsOfflineCount = { unreadItemsOfflineCount }
229
- starredItemsCount = { starredItemsCount }
230
- starredItemsOfflineCount = { starredItemsOfflineCount }
231
- sourcesState = { sourcesState }
232
- setSourcesState = { setSourcesState }
233
- sources = { sources }
234
- setSources = { setSources }
235
- tags = { tags }
236
- reloadAll = { reloadAll }
237
- />
227
+ { /* navigation */ }
228
+ < Collapse isOpen = { ! smartphone || navExpanded } className = "collapse-css-transition" >
229
+ < div id = "nav" role = "navigation" >
230
+ < Navigation
231
+ entriesPage = { entriesPage }
232
+ setNavExpanded = { setNavExpanded }
233
+ navSourcesExpanded = { navSourcesExpanded }
234
+ setNavSourcesExpanded = { setNavSourcesExpanded }
235
+ offlineState = { offlineState }
236
+ allItemsCount = { allItemsCount }
237
+ allItemsOfflineCount = { allItemsOfflineCount }
238
+ unreadItemsCount = { unreadItemsCount }
239
+ unreadItemsOfflineCount = { unreadItemsOfflineCount }
240
+ starredItemsCount = { starredItemsCount }
241
+ starredItemsOfflineCount = { starredItemsOfflineCount }
242
+ sourcesState = { sourcesState }
243
+ setSourcesState = { setSourcesState }
244
+ sources = { sources }
245
+ setSources = { setSources }
246
+ tags = { tags }
247
+ reloadAll = { reloadAll }
248
+ />
249
+ </ div >
250
+ </ Collapse >
251
+
252
+ < ul id = "search-list" >
253
+ < SearchList />
254
+ </ ul >
255
+
256
+ { /* content */ }
257
+ < div id = "content" role = "main" >
258
+ < Routes >
259
+ < Route
260
+ path = "/"
261
+ element = {
262
+ < Redirect to = { `/${ homePagePath . join ( '/' ) } ` } />
263
+ }
264
+ />
265
+ < Route
266
+ /* TODO: regex pattern does not work https://github.com/remix-run/react-router/issues/8254 */
267
+ path = { ENTRIES_ROUTE_PATTERN }
268
+ element = {
269
+ < EntriesPage
270
+ ref = { entriesRef }
271
+ setNavExpanded = { setNavExpanded }
272
+ configuration = { configuration }
273
+ navSourcesExpanded = { navSourcesExpanded }
274
+ setTitle = { setTitle }
275
+ unreadItemsCount = { unreadItemsCount }
276
+ />
277
+ }
278
+ />
279
+ < Route
280
+ path = "/manage/sources"
281
+ element = {
282
+ < SourcesPage />
283
+ }
284
+ />
285
+ < Route
286
+ path = "*"
287
+ element = {
288
+ < NotFound />
289
+ }
290
+ />
291
+ </ Routes >
238
292
</ div >
239
- </ Collapse >
240
-
241
- < ul id = "search-list" >
242
- < SearchList />
243
- </ ul >
244
-
245
- { /* content */ }
246
- < div id = "content" role = "main" >
247
- < Switch >
248
- < Route exact path = "/" >
249
- < Redirect to = { `/${ homePagePath . join ( '/' ) } ` } />
250
- </ Route >
251
- < Route path = { ENTRIES_ROUTE_PATTERN } >
252
- { ( routeProps ) => (
253
- < EntriesPage
254
- { ...routeProps }
255
- ref = { entriesRef }
256
- setNavExpanded = { setNavExpanded }
257
- configuration = { configuration }
258
- navSourcesExpanded = { navSourcesExpanded }
259
- setTitle = { setTitle }
260
- unreadItemsCount = { unreadItemsCount }
261
- />
262
- ) }
263
- </ Route >
264
- < Route path = "/manage/sources" >
265
- < SourcesPage />
266
- </ Route >
267
- < Route path = "*" >
268
- < NotFound />
269
- </ Route >
270
- </ Switch >
271
- </ div >
272
- </ CheckAuthorization >
273
- </ Route >
274
- </ Switch >
293
+ </ CheckAuthorization >
294
+ }
295
+ />
296
+ </ Routes >
275
297
</ React . StrictMode >
276
298
) ;
277
299
}
0 commit comments