Skip to content

Commit

Permalink
style: move items from side menu to header (#540)
Browse files Browse the repository at this point in the history
Co-authored-by: Noam Gaash <noam.gaash@gmail.com>
  • Loading branch information
YuvalMasada and NoamGaash authored Mar 6, 2024
1 parent 04518e6 commit d8b1a55
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 35 deletions.
29 changes: 0 additions & 29 deletions src/layout/header/GitHubLink/GitHubLink.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/layout/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useContext } from 'react'
import { LayoutContextInterface, LayoutCtx } from '../LayoutContext'
import { useTheme } from '../ThemeContext'
import { MenuOutlined } from '@ant-design/icons'
import GitHubLink from './GitHubLink/GitHubLink'
import './Header.css'
import cn from 'classnames'
import ToggleThemeButton from './ToggleThemeButton'
import HeaderLinks from './HeaderLinks/HeaderLinks'

const { Header } = Layout

Expand All @@ -17,8 +17,8 @@ const MainHeader = () => {
<Header className={cn('main-header', { dark: isDarkTheme })}>
<MenuOutlined onClick={() => setDrawerOpen(true)} className="hideOnDesktop" />
<div style={{ flex: 1 }}>&nbsp;</div>
<GitHubLink />
<ToggleThemeButton toggleTheme={toggleTheme} isDarkTheme={isDarkTheme} />
<HeaderLinks />
</Header>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
.github-link {
.header-links {
display: flex;
margin-right: 10px;
}

.header-link {
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
padding-inline: 5px;
cursor: pointer;
transition: all 0.1s;

Expand Down
54 changes: 54 additions & 0 deletions src/layout/header/HeaderLinks/HeaderLinks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { FC } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'

import './HeaderLinks.scss'
import { HEADER_LINKS } from 'src/routes'

type LinkType = Omit<(typeof HEADER_LINKS)[number], 'element'>

const HeaderLinks: FC = () => {
return (
<div className="header-links">
{HEADER_LINKS.map((item) => {
if (item.element === null) {
return (
<ExternalLink key={item.label} label={item.label} icon={item.icon} path={item.path} />
)
} else {
return (
<InternalLink key={item.label} label={item.label} icon={item.icon} path={item.path} />
)
}
})}
</div>
)
}

const ExternalLink = ({ label, path, icon }: LinkType) => {
const { t } = useTranslation()
function handleClick() {
window.open(path, '_blank')
}
return (
<div className="header-link" aria-label={t(label)} title={t(label)} onClick={handleClick}>
{icon}
</div>
)
}

const InternalLink = ({ label, path, icon }: LinkType) => {
const navigate = useNavigate()
const { t } = useTranslation()
return (
<div
aria-label={t(label)}
title={t(label)}
className="header-link"
onClick={() => navigate(path)}>
{icon}
</div>
)
}

export default HeaderLinks
16 changes: 14 additions & 2 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const About = lazy(() => import('../pages/about'))
const Profile = lazy(() => import('../pages/Profile'))
const BugReportForm = lazy(() => import('../pages/BugReportForm '))
const DataResearch = lazy(() =>
import('../pages/DataResearch/DataResearch').then((m) => ({ default: m.DataResearch })),
import('../pages/DataResearch/DataResearch').then((m) => ({
default: m.DataResearch,
})),
)

import {
Expand All @@ -26,6 +28,7 @@ import {
BugOutlined,
BarChartOutlined,
LineChartOutlined,
GithubOutlined,
} from '@ant-design/icons'
import { MainRoute } from './MainRoute'
import { ErrorPage } from 'src/pages/ErrorPage'
Expand Down Expand Up @@ -76,6 +79,9 @@ export const PAGES = [
icon: <InfoCircleOutlined />,
element: <About />,
},
] as const

export const HEADER_LINKS = [
{
label: 'report_a_bug_title',
path: 'report-a-bug',
Expand All @@ -88,6 +94,12 @@ export const PAGES = [
icon: <DollarOutlined />,
element: null,
},
{
label: 'github_link',
path: 'https://github.com/hasadna/open-bus-map-search',
icon: <GithubOutlined />,
element: null,
},
] as const

const HIDDEN_PAGES = [
Expand All @@ -106,7 +118,7 @@ const HIDDEN_PAGES = [
] as const

const getRoutesList = () => {
const pages = [...PAGES, ...HIDDEN_PAGES]
const pages = [...PAGES, ...HIDDEN_PAGES, ...HEADER_LINKS]
const RedirectToDashboard = () => <Navigate to={pages[0].path} replace />
const routes = pages.filter((r) => r.element)
return (
Expand Down
1 change: 0 additions & 1 deletion tests/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ test('menu', async ({ page }) => {
'מפה בזמן אמת',
'מפה לפי קו',
'אודות',
'לתרומות',
]
await expect(page.locator('ul > li a')).toContainText(menuItemsInOrder)
})

0 comments on commit d8b1a55

Please sign in to comment.