Skip to content

Commit

Permalink
fix(mobile): close menu after navigation (#414)
Browse files Browse the repository at this point in the history
Co-authored-by: moshe vilner <shootermv@gmail.com>
Co-authored-by: Noam Gaash <noam.gaash@applitools.com>
  • Loading branch information
3 people committed Feb 7, 2024
1 parent cc1f9bb commit e99683f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/layout/sidebar/menu/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect, useState, useContext } from 'react'
import { Link, useLocation } from 'react-router-dom'
import './menu.scss'
import { useTranslation } from 'react-i18next'
import { PAGES } from 'src/routes'

import type { MenuProps } from 'antd'
import { Menu } from 'antd'
import { LayoutContextInterface, LayoutCtx } from 'src/layout/LayoutContext'
import { LanguageToggle } from 'src/pages/EasterEgg/LanguageToggle'

type MenuItem = Required<MenuProps>['items'][number]
function getItem(
label: React.ReactNode,
Expand All @@ -25,9 +25,15 @@ function getItem(

const MainMenu = () => {
const { t } = useTranslation()
const { setDrawerOpen } = useContext<LayoutContextInterface>(LayoutCtx)
const items: MenuItem[] = PAGES.map((itm) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return getItem(<Link to={t(itm.path as any)}>{t(itm.label as any)}</Link>, itm.path, itm.icon)
return getItem(
<Link to={itm.path} onClick={() => setDrawerOpen(false)}>
{t(itm.label)}
</Link>,
itm.path,
itm.icon,
)
})

const location = useLocation()
Expand Down
2 changes: 1 addition & 1 deletion src/routes/MainRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const MainRoute = () => {

useEffect(() => {
const page = PAGES.find((page) => page.path === location.pathname)
if (page?.searchParamsRequired) {
if (page && 'searchParamsRequired' in page && page.searchParamsRequired) {
const params = new URLSearchParams({ timestamp: search.timestamp.toString() })

if (search.operatorId) {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const PAGES = [
icon: <DollarOutlined />,
element: null,
},
]
] as const

const HIDDEN_PAGES = [
{
Expand All @@ -103,10 +103,10 @@ const HIDDEN_PAGES = [
icon: <InfoCircleOutlined />,
element: <DataResearch />,
},
]
] as const

const getRoutesList = () => {
const pages = PAGES.concat(HIDDEN_PAGES)
const pages = [...PAGES, ...HIDDEN_PAGES]
const RedirectToDashboard = () => <Navigate to={pages[0].path} replace />
const routes = pages.filter((r) => r.element)
return (
Expand Down

0 comments on commit e99683f

Please sign in to comment.