Skip to content

Commit

Permalink
feat: added main link to the Navbar main menu and changed Navbar beha…
Browse files Browse the repository at this point in the history
…viour
  • Loading branch information
braianj committed Jul 11, 2024
1 parent 0f2aa5e commit b0fff9d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/components/Navbar/MainMenu/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from 'react'
import classNames from 'classnames'

import { MenuItem } from '../MenuItem/MenuItem'
import { NavbarPages } from '../Navbar.types'
import { NavbarPages, NavbarPagesUrls } from '../Navbar.types'
import { MainMenuProps } from './MainMenu.types'

import './MainMenu.css'

export const MainMenu = (props: MainMenuProps) => {
const { i18n, ...menuItemProps } = props

return (
<div
className={classNames(
Expand All @@ -21,26 +22,31 @@ export const MainMenu = (props: MainMenuProps) => {
{...menuItemProps}
section={NavbarPages.MARKETPLACE}
title={i18n.marketplace}
mainUrl={NavbarPagesUrls[NavbarPages.MARKETPLACE.toUpperCase()]}
/>
<MenuItem
{...menuItemProps}
section={NavbarPages.CREATE}
title={i18n.create}
mainUrl={NavbarPagesUrls[NavbarPages.CREATE.toUpperCase()]}
/>
<MenuItem
{...menuItemProps}
section={NavbarPages.EXPLORE}
title={i18n.explore}
mainUrl={NavbarPagesUrls[NavbarPages.EXPLORE.toUpperCase()]}
/>
<MenuItem
{...menuItemProps}
section={NavbarPages.LEARN}
title={i18n.learn}
mainUrl={NavbarPagesUrls[NavbarPages.LEARN.toUpperCase()]}
/>
<MenuItem
{...menuItemProps}
section={NavbarPages.GOVERNANCE}
title={i18n.governance}
mainUrl={NavbarPagesUrls[NavbarPages.GOVERNANCE.toUpperCase()]}
/>
</div>
)
Expand Down
27 changes: 17 additions & 10 deletions src/components/Navbar/MenuItem/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useCallback } from 'react'
import Menu from 'semantic-ui-react/dist/commonjs/collections/Menu'
import classNames from 'classnames'

Expand All @@ -9,24 +9,31 @@ import { MenuItemProps } from './MenuItem.types'
import './MenuItem.css'

export const MenuItem = (props: MenuItemProps) => {
const { activePage, section, title, onToggleShowSubMenu, isMobile } = props
const { activePage, section, title, onToggleShowSubMenu, isMobile, mainUrl } =
props

const mainRedirect = useCallback(() => {
mainUrl && window.open(mainUrl, '_self')
}, [mainUrl])

return (
<Menu.Item
active={activePage === section}
onMouseEnter={(e: React.MouseEvent) =>
!isMobile && onToggleShowSubMenu(e, true, section)
}
onMouseLeave={(e: React.MouseEvent) =>
!isMobile && onToggleShowSubMenu(e, false, section)
}
onClick={(e: React.MouseEvent) => {
isMobile && onToggleShowSubMenu(e, true, section)
}}
className={classNames('dui-menu-item', section, isMobile && 'mobile')}
>
{title}
{!isMobile && <ChevronIcon down={true} />}
<div onClick={mainRedirect}>{title}</div>
{!isMobile && (
<div
onClick={(e: React.MouseEvent) => {
onToggleShowSubMenu(e, true, section)
}}
>
<ChevronIcon down={true} />
</div>
)}
{isMobile && <ArrowIcon />}
</Menu.Item>
)
Expand Down
1 change: 1 addition & 0 deletions src/components/Navbar/MenuItem/MenuItem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export type MenuItemProps = {
show: boolean,
section?: NavbarPages
) => void
mainUrl?: string
isMobile?: boolean
}
8 changes: 8 additions & 0 deletions src/components/Navbar/Navbar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export enum NavbarPages {
GOVERNANCE = 'governance'
}

export enum NavbarPagesUrls {
MARKETPLACE = 'https://decentraland.org/marketplace',
CREATE = 'https://decentraland.org/create/',
EXPLORE = 'https://decentraland.org/events/',
LEARN = 'https://docs.decentraland.org/player/',
GOVERNANCE = 'https://decentraland.org/governance/'
}

export type NavbarMenuI18nProps = Record<NavbarPages, NavbarPages>

export type NavbarSubMenuItemsProps = {
Expand Down

0 comments on commit b0fff9d

Please sign in to comment.