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
+15 -4
View File
@@ -1,8 +1,9 @@
import React, { FC, useMemo, useState } from "react"
import React, { FC, useEffect, useMemo, useState } from "react"
import useLocation from "./hooks/useLocation"
export interface ISidebarContextInterface {
current: number
setCurrent: (index: number) => void
current: string | null
setCurrent: (key: string) => void
openOnMobile: boolean
setOpenOnMobile: (active: boolean) => void
}
@@ -12,9 +13,19 @@ export const SidebarContext = React.createContext<ISidebarContextInterface | nul
)
export const SidebarProvider: FC = ({ children }) => {
const [current, setCurrent] = useState(0)
const { location, getSecondLevel } = useLocation()
const [current, setCurrent] = useState<string | null>(null)
const [openOnMobile, setOpenOnMobile] = useState(false)
useEffect(() => {
if (location && location.pathname) {
const secondLevel = getSecondLevel(location.pathname)
setCurrent(secondLevel || null)
} else {
setCurrent(null)
}
}, [location])
const memoizedContextValue = useMemo(
() => ({
current,