@@ -80,7 +80,7 @@ const ProfileLabel = styled(IonLabel)`
80
80
` ;
81
81
82
82
export default function TabbedRoutes ( ) {
83
- const { activePage } = useContext ( AppContext ) ;
83
+ const { activePageRef } = useContext ( AppContext ) ;
84
84
const location = useLocation ( ) ;
85
85
const router = useIonRouter ( ) ;
86
86
const jwt = useAppSelector ( jwtSelector ) ;
@@ -145,7 +145,7 @@ export default function TabbedRoutes() {
145
145
async function onPostsClick ( ) {
146
146
if ( ! isPostsButtonDisabled ) return ;
147
147
148
- if ( await scrollUpIfNeeded ( activePage ) ) return ;
148
+ if ( await scrollUpIfNeeded ( activePageRef ?. current ) ) return ;
149
149
150
150
if ( location . pathname . endsWith ( jwt ? "/home" : "/all" ) ) {
151
151
router . push ( `/posts/${ actor ?? iss ?? getDefaultServer ( ) } ` , "back" ) ;
@@ -172,15 +172,15 @@ export default function TabbedRoutes() {
172
172
async function onInboxClick ( ) {
173
173
if ( ! isInboxButtonDisabled ) return ;
174
174
175
- if ( await scrollUpIfNeeded ( activePage ) ) return ;
175
+ if ( await scrollUpIfNeeded ( activePageRef ?. current ) ) return ;
176
176
177
177
router . push ( `/inbox` , "back" ) ;
178
178
}
179
179
180
180
async function onProfileClick ( ) {
181
181
if ( ! isProfileButtonDisabled ) return ;
182
182
183
- if ( await scrollUpIfNeeded ( activePage ) ) return ;
183
+ if ( await scrollUpIfNeeded ( activePageRef ?. current ) ) return ;
184
184
185
185
router . push ( "/profile" , "back" ) ;
186
186
}
@@ -191,7 +191,7 @@ export default function TabbedRoutes() {
191
191
// if the search page is already open, focus the search bar
192
192
focusSearchBar ( ) ;
193
193
194
- if ( await scrollUpIfNeeded ( activePage ) ) return ;
194
+ if ( await scrollUpIfNeeded ( activePageRef ?. current ) ) return ;
195
195
196
196
router . push ( `/search` , "back" ) ;
197
197
}
@@ -270,153 +270,163 @@ export default function TabbedRoutes() {
270
270
] ;
271
271
}
272
272
273
+ const pageContextValue = useMemo ( ( ) => ( { pageRef } ) , [ ] ) ;
274
+
275
+ // Ideally this would be a separate component,
276
+ // but that is not currently supported in Ionic React
277
+ // So memoize instead (since this is expensive to build)
278
+ const routes = useMemo (
279
+ ( ) => (
280
+ < IonRouterOutlet ref = { pageRef } >
281
+ < Route exact path = "/" >
282
+ < Redirect
283
+ to = { `/posts/${ iss ?? getDefaultServer ( ) } /${ iss ? "home" : "all" } ` }
284
+ push = { false }
285
+ />
286
+ </ Route >
287
+ < Route exact path = "/posts/:actor/home" >
288
+ < ActorRedirect >
289
+ < SpecialFeedPage type = "Subscribed" />
290
+ </ ActorRedirect >
291
+ </ Route >
292
+ < Route exact path = "/posts/:actor/all" >
293
+ < ActorRedirect >
294
+ < SpecialFeedPage type = "All" />
295
+ </ ActorRedirect >
296
+ </ Route >
297
+ < Route exact path = "/posts/:actor/local" >
298
+ < ActorRedirect >
299
+ < SpecialFeedPage type = "Local" />
300
+ </ ActorRedirect >
301
+ </ Route >
302
+ < Route exact path = "/posts/:actor" >
303
+ < ActorRedirect >
304
+ < CommunitiesPage />
305
+ </ ActorRedirect >
306
+ </ Route >
307
+ { ...buildGeneralBrowseRoutes ( "posts" ) }
308
+
309
+ < Route exact path = "/inbox" >
310
+ < BoxesPage />
311
+ </ Route >
312
+ < Route exact path = "/inbox/all" >
313
+ < InboxAuthRequired >
314
+ < InboxPage showRead />
315
+ </ InboxAuthRequired >
316
+ </ Route >
317
+ < Route exact path = "/inbox/unread" >
318
+ < InboxAuthRequired >
319
+ < InboxPage />
320
+ </ InboxAuthRequired >
321
+ </ Route >
322
+ < Route exact path = "/inbox/mentions" >
323
+ < InboxAuthRequired >
324
+ < MentionsPage />
325
+ </ InboxAuthRequired >
326
+ </ Route >
327
+ < Route exact path = "/inbox/comment-replies" >
328
+ < InboxAuthRequired >
329
+ < RepliesPage type = "Comment" />
330
+ </ InboxAuthRequired >
331
+ </ Route >
332
+ < Route exact path = "/inbox/post-replies" >
333
+ < InboxAuthRequired >
334
+ < RepliesPage type = "Post" />
335
+ </ InboxAuthRequired >
336
+ </ Route >
337
+ < Route exact path = "/inbox/messages" >
338
+ < InboxAuthRequired >
339
+ < MessagesPage />
340
+ </ InboxAuthRequired >
341
+ </ Route >
342
+ < Route exact path = "/inbox/messages/:handle" >
343
+ < InboxAuthRequired >
344
+ < ConversationPage />
345
+ </ InboxAuthRequired >
346
+ </ Route >
347
+ { ...buildGeneralBrowseRoutes ( "inbox" ) }
348
+
349
+ < Route exact path = "/profile" >
350
+ < ProfilePage />
351
+ </ Route >
352
+ { ...buildGeneralBrowseRoutes ( "profile" ) }
353
+ < Route exact path = "/profile/:actor" >
354
+ < Redirect to = "/profile" push = { false } />
355
+ </ Route >
356
+
357
+ < Route exact path = "/search" >
358
+ < SearchPage />
359
+ </ Route >
360
+ < Route exact path = "/search/posts/:search" >
361
+ < SearchPostsResultsPage type = "Posts" />
362
+ </ Route >
363
+ < Route exact path = "/search/comments/:search" >
364
+ < SearchPostsResultsPage type = "Comments" />
365
+ </ Route >
366
+ < Route exact path = "/search/communities/:search" >
367
+ < SearchCommunitiesPage />
368
+ </ Route >
369
+ { ...buildGeneralBrowseRoutes ( "search" ) }
370
+ < Route exact path = "/search/:actor" >
371
+ < Redirect to = "/search" push = { false } />
372
+ </ Route >
373
+
374
+ < Route exact path = "/settings" >
375
+ < SettingsPage />
376
+ </ Route >
377
+ < Route exact path = "/settings/terms" >
378
+ < TermsPage />
379
+ </ Route >
380
+ < Route exact path = "/settings/install" >
381
+ < InstallAppPage />
382
+ </ Route >
383
+ < Route exact path = "/settings/update" >
384
+ < UpdateAppPage />
385
+ </ Route >
386
+ < Route exact path = "/settings/general" >
387
+ < GeneralPage />
388
+ </ Route >
389
+ < Route exact path = "/settings/general/hiding" >
390
+ < HidingSettingsPage />
391
+ </ Route >
392
+ < Route exact path = "/settings/appearance" >
393
+ < AppearancePage />
394
+ </ Route >
395
+ < Route exact path = "/settings/appearance/theme" >
396
+ < AppearanceThemePage />
397
+ </ Route >
398
+ < Route exact path = "/settings/appearance/theme/mode" >
399
+ < DeviceModeSettingsPage />
400
+ </ Route >
401
+ < Route exact path = "/settings/gestures" >
402
+ < GesturesPage />
403
+ </ Route >
404
+ < Route exact path = "/settings/blocks" >
405
+ < BlocksSettingsPage />
406
+ </ Route >
407
+ < Route exact path = "/settings/reddit-migrate" >
408
+ < RedditMigratePage />
409
+ </ Route >
410
+ < Route exact path = "/settings/reddit-migrate/:search" >
411
+ < SearchCommunitiesPage />
412
+ </ Route >
413
+ { /* general routes for settings is only for reddit-migrate */ }
414
+ { ...buildGeneralBrowseRoutes ( "settings" ) }
415
+ </ IonRouterOutlet >
416
+ ) ,
417
+ [ iss ]
418
+ ) ;
419
+
273
420
if ( ! ready ) return ;
274
421
275
422
return (
276
- < PageContextProvider value = { { page : pageRef . current as HTMLElement } } >
423
+ < PageContextProvider value = { pageContextValue } >
277
424
< GalleryProvider >
278
425
{ /* TODO key={} resets the tab route stack whenever your instance changes. */ }
279
426
{ /* In the future, it would be really cool if we could resolve object urls to pick up where you left off */ }
280
427
{ /* But this isn't trivial with needing to rewrite URLs... */ }
281
428
< IonTabs key = { iss ?? getDefaultServer ( ) } >
282
- < IonRouterOutlet ref = { pageRef } >
283
- < Route exact path = "/" >
284
- < Redirect
285
- to = { `/posts/${ iss ?? getDefaultServer ( ) } /${
286
- iss ? "home" : "all"
287
- } `}
288
- push = { false }
289
- />
290
- </ Route >
291
- < Route exact path = "/posts/:actor/home" >
292
- < ActorRedirect >
293
- < SpecialFeedPage type = "Subscribed" />
294
- </ ActorRedirect >
295
- </ Route >
296
- < Route exact path = "/posts/:actor/all" >
297
- < ActorRedirect >
298
- < SpecialFeedPage type = "All" />
299
- </ ActorRedirect >
300
- </ Route >
301
- < Route exact path = "/posts/:actor/local" >
302
- < ActorRedirect >
303
- < SpecialFeedPage type = "Local" />
304
- </ ActorRedirect >
305
- </ Route >
306
- < Route exact path = "/posts/:actor" >
307
- < ActorRedirect >
308
- < CommunitiesPage />
309
- </ ActorRedirect >
310
- </ Route >
311
- { ...buildGeneralBrowseRoutes ( "posts" ) }
312
-
313
- < Route exact path = "/inbox" >
314
- < BoxesPage />
315
- </ Route >
316
- < Route exact path = "/inbox/all" >
317
- < InboxAuthRequired >
318
- < InboxPage showRead />
319
- </ InboxAuthRequired >
320
- </ Route >
321
- < Route exact path = "/inbox/unread" >
322
- < InboxAuthRequired >
323
- < InboxPage />
324
- </ InboxAuthRequired >
325
- </ Route >
326
- < Route exact path = "/inbox/mentions" >
327
- < InboxAuthRequired >
328
- < MentionsPage />
329
- </ InboxAuthRequired >
330
- </ Route >
331
- < Route exact path = "/inbox/comment-replies" >
332
- < InboxAuthRequired >
333
- < RepliesPage type = "Comment" />
334
- </ InboxAuthRequired >
335
- </ Route >
336
- < Route exact path = "/inbox/post-replies" >
337
- < InboxAuthRequired >
338
- < RepliesPage type = "Post" />
339
- </ InboxAuthRequired >
340
- </ Route >
341
- < Route exact path = "/inbox/messages" >
342
- < InboxAuthRequired >
343
- < MessagesPage />
344
- </ InboxAuthRequired >
345
- </ Route >
346
- < Route exact path = "/inbox/messages/:handle" >
347
- < InboxAuthRequired >
348
- < ConversationPage />
349
- </ InboxAuthRequired >
350
- </ Route >
351
- { ...buildGeneralBrowseRoutes ( "inbox" ) }
352
-
353
- < Route exact path = "/profile" >
354
- < ProfilePage />
355
- </ Route >
356
- { ...buildGeneralBrowseRoutes ( "profile" ) }
357
- < Route exact path = "/profile/:actor" >
358
- < Redirect to = "/profile" push = { false } />
359
- </ Route >
360
-
361
- < Route exact path = "/search" >
362
- < SearchPage />
363
- </ Route >
364
- < Route exact path = "/search/posts/:search" >
365
- < SearchPostsResultsPage type = "Posts" />
366
- </ Route >
367
- < Route exact path = "/search/comments/:search" >
368
- < SearchPostsResultsPage type = "Comments" />
369
- </ Route >
370
- < Route exact path = "/search/communities/:search" >
371
- < SearchCommunitiesPage />
372
- </ Route >
373
- { ...buildGeneralBrowseRoutes ( "search" ) }
374
- < Route exact path = "/search/:actor" >
375
- < Redirect to = "/search" push = { false } />
376
- </ Route >
377
-
378
- < Route exact path = "/settings" >
379
- < SettingsPage />
380
- </ Route >
381
- < Route exact path = "/settings/terms" >
382
- < TermsPage />
383
- </ Route >
384
- < Route exact path = "/settings/install" >
385
- < InstallAppPage />
386
- </ Route >
387
- < Route exact path = "/settings/update" >
388
- < UpdateAppPage />
389
- </ Route >
390
- < Route exact path = "/settings/general" >
391
- < GeneralPage />
392
- </ Route >
393
- < Route exact path = "/settings/general/hiding" >
394
- < HidingSettingsPage />
395
- </ Route >
396
- < Route exact path = "/settings/appearance" >
397
- < AppearancePage />
398
- </ Route >
399
- < Route exact path = "/settings/appearance/theme" >
400
- < AppearanceThemePage />
401
- </ Route >
402
- < Route exact path = "/settings/appearance/theme/mode" >
403
- < DeviceModeSettingsPage />
404
- </ Route >
405
- < Route exact path = "/settings/gestures" >
406
- < GesturesPage />
407
- </ Route >
408
- < Route exact path = "/settings/blocks" >
409
- < BlocksSettingsPage />
410
- </ Route >
411
- < Route exact path = "/settings/reddit-migrate" >
412
- < RedditMigratePage />
413
- </ Route >
414
- < Route exact path = "/settings/reddit-migrate/:search" >
415
- < SearchCommunitiesPage />
416
- </ Route >
417
- { /* general routes for settings is only for reddit-migrate */ }
418
- { ...buildGeneralBrowseRoutes ( "settings" ) }
419
- </ IonRouterOutlet >
429
+ { routes }
420
430
< IonTabBar slot = "bottom" >
421
431
< IonTabButton
422
432
disabled = { isPostsButtonDisabled }
0 commit comments