@@ -18,7 +18,7 @@ import { profileContext, ProfileContextData } from '../profile-provider'
1818import { PlatformRoute } from './platform-route.model'
1919import { RequireAuthProvider } from './require-auth-provider'
2020import { RouteContextData } from './route-context-data.model'
21- import { routeGetSignupUrl , routeIsActiveTool } from './route-functions'
21+ import { routeGetActive , routeGetSignupUrl } from './route-functions'
2222import { default as routeContext , defaultRouteContextData } from './route.context'
2323
2424interface RouteProviderProps {
@@ -47,39 +47,14 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
4747 // TODO: try to make these prop names configurable instead of hard-codded
4848 const toolsRoutes : Array < PlatformRoute > = props . toolsRoutes . filter ( route => ! route . disabled )
4949
50- // display a tool in the nav if the following conditions are met:
51- // 1. the tool has a title
52- // 2. the tool isn't hidden (if the tool is hidden, it should never appear in the nav)
53- // AND
54- // 3. the tool is one of the following:
55- // a. for customers and the user is a customer
56- // b. for members and the user is a member
57- // c. the active tool in the app (in case someone deep-links to it)
58- let activeRoute : PlatformRoute | undefined
59- const toolsRoutesForNav : Array < PlatformRoute > = toolsRoutes
60- . filter ( route => {
61-
62- const isActive : boolean = routeIsActiveTool ( location . pathname , route )
63- if ( isActive ) {
64- activeRoute = route
65- }
66-
67- return ! ! route . title
68- && ! route . hidden
69- && (
70- (
71- ( ! route . customerOnly || ! ! profile ?. isCustomer )
72- && ( ! route . memberOnly || ! ! profile ?. isMember )
73- )
74- || isActive
75- )
76- } )
77-
7850 const utilsRoutes : Array < PlatformRoute > = props . utilsRoutes . filter ( route => ! route . disabled )
7951 allRoutes = [
8052 ...toolsRoutes ,
8153 ...utilsRoutes ,
8254 ]
55+
56+ const activeRoute : PlatformRoute | undefined = routeGetActive ( location . pathname , allRoutes )
57+
8358 // TODO: support additional roles and landing pages
8459 const loggedInRoot : string = ! profile
8560 ? ''
@@ -88,12 +63,11 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
8863 : props . rootMember
8964
9065 const contextData : RouteContextData = {
91- activeToolName : activeRoute ?. title ,
66+ activeToolName : activeRoute ?. title || activeRoute ?. id ,
9267 activeToolRoute : ! ! activeRoute ? `https://${ window . location . hostname } ${ activeRoute . route } ` : undefined ,
9368 allRoutes,
9469 getChildren,
9570 getChildRoutes,
96- getPath,
9771 getPathFromRoute,
9872 getRouteElement,
9973 getSignupUrl : routeGetSignupUrl ,
@@ -102,15 +76,14 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
10276 rootLoggedInRoute : loggedInRoot ,
10377 rootLoggedOutFC : props . rootLoggedOutFC ,
10478 toolsRoutes,
105- toolsRoutesForNav,
10679 utilsRoutes,
10780 }
10881 setRouteContextData ( contextData )
10982 }
11083
11184 function getChildren ( parent : string ) : Array < PlatformRoute > {
11285 return allRoutes
113- . find ( route => route . title === parent )
86+ . find ( route => route . id === parent )
11487 ?. children
11588 || [ ]
11689 }
@@ -120,12 +93,6 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
12093 . map ( route => getRouteElement ( route ) )
12194 }
12295
123- function getPath ( routeTitle : string ) : string {
124- const platformRoute : PlatformRoute = allRoutes . find ( route => route . title === routeTitle ) as PlatformRoute
125- // if the path has a trailing asterisk, remove it
126- return getPathFromRoute ( platformRoute )
127- }
128-
12996 function getPathFromRoute ( route : PlatformRoute ) : string {
13097 return route . route . replace ( '/*' , '' )
13198 }
0 commit comments