feat(resources): make languages collapsible

This commit is contained in:
Jean-Philippe Sirois
2020-01-18 02:55:10 -05:00
parent 423c9949b6
commit 0a9484ffae
6 changed files with 164 additions and 65 deletions
+11 -3
View File
@@ -5,10 +5,17 @@ function appendSlashToPath(path: string): string {
return path.endsWith("/") ? path : `${path}/`
}
function getSecondLevel(path: string): string | void {
const [, , secondLevel] = path.split("/")
return secondLevel
}
export interface ILocationContextInterface {
location: WindowLocation | void
isHome: boolean
isMatchingPath: (path: string) => boolean
getSecondLevel: (path: string) => string | void
}
interface ILocationProviderProps {
@@ -19,9 +26,9 @@ export const LocationContext = React.createContext<ILocationContextInterface | n
null
)
export const LocationProvider: FC<
PropsWithChildren<ILocationProviderProps>
> = ({ children, location }) => {
export const LocationProvider: FC<PropsWithChildren<
ILocationProviderProps
>> = ({ children, location }) => {
const memoizedContextValue = useMemo(
() => ({
location,
@@ -31,6 +38,7 @@ export const LocationProvider: FC<
? appendSlashToPath(location.pathname).startsWith(path)
: false
},
getSecondLevel,
}),
[location]
)