11import { observer } from 'mobx-react' ;
22import dynamic from 'next/dynamic' ;
33import { useRouter } from 'next/router' ;
4- import { FC , useContext } from 'react' ;
5- import { Container , Nav , Navbar } from 'react-bootstrap' ;
4+ import { AnchorHTMLAttributes , FC , useContext } from 'react' ;
5+ import { Container , Image , Nav , Navbar , NavDropdown } from 'react-bootstrap' ;
66
7+ import { DefaultImage } from '../../models/configuration' ;
78import { i18n , I18nContext } from '../../models/Translation' ;
89
910const LanguageMenu = dynamic ( ( ) => import ( './LanguageMenu' ) , { ssr : false } ) ;
1011
11- export type MenuItem = Record < 'href' | 'name' , string > ;
12+ export interface MenuItem extends Pick < AnchorHTMLAttributes < HTMLAnchorElement > , 'href' | 'title' > {
13+ subs ?: MenuItem [ ] ;
14+ }
1215
1316const topNavBarMenu = ( { t } : typeof i18n ) : MenuItem [ ] => [
14- { href : '/article/about' , name : t ( 'about' ) } ,
15- { href : '/article/history' , name : t ( 'history' ) } ,
16- { href : '/article/code-of-conduct' , name : t ( 'code_of_conduct' ) } ,
17- { href : '/article/join-us' , name : t ( 'join_us' ) } ,
1817 {
19- href : '/article/open-collaborator-award' ,
20- name : t ( 'open_collaborator_award' ) ,
18+ title : t ( 'about' ) ,
19+ subs : [
20+ { href : '/article/about' , title : t ( 'about' ) } ,
21+ { href : '/article/history' , title : t ( 'history' ) } ,
22+ { href : '/article/code-of-conduct' , title : t ( 'code_of_conduct' ) } ,
23+ ] ,
24+ } ,
25+ {
26+ title : t ( 'join_us' ) ,
27+ subs : [
28+ { href : '/article/join-us' , title : t ( 'join_us' ) } ,
29+ {
30+ href : '/article/open-collaborator-award' ,
31+ title : t ( 'open_collaborator_award' ) ,
32+ } ,
33+ { href : '/volunteer' , title : t ( 'volunteer' ) } ,
34+ ] ,
35+ } ,
36+ {
37+ title : t ( 'open_source_projects' ) ,
38+ subs : [
39+ { href : '/project' , title : t ( 'open_source_projects' ) } ,
40+ { href : '/issue' , title : 'GitHub issues' } ,
41+ {
42+ href : 'https://github.com/Open-Source-Bazaar/Git-Hackathon-scaffold' ,
43+ title : t ( 'hackathon' ) ,
44+ } ,
45+ { href : '/license-filter' , title : t ( 'license_filter' ) } ,
46+ ] ,
2147 } ,
22- { href : '/volunteer' , name : t ( 'volunteer' ) } ,
23- { href : '/project' , name : t ( 'open_source_projects' ) } ,
24- { href : '/issue' , name : 'GitHub issues' } ,
2548 {
26- href : 'https://github.com/Open-Source-Bazaar/Git-Hackathon-scaffold' ,
27- name : t ( 'hackathon' ) ,
49+ title : t ( 'wiki' ) ,
50+ subs : [
51+ { href : '/wiki' , title : t ( 'wiki' ) } ,
52+ { href : '/policy' , title : t ( 'policy' ) } ,
53+ ] ,
2854 } ,
29- { href : '/license-filter' , name : t ( 'license_filter' ) } ,
30- { href : '/policy' , name : t ( 'policy' ) } ,
3155] ;
3256
3357export interface MainNavigatorProps {
@@ -44,21 +68,32 @@ export const MainNavigator: FC<MainNavigatorProps> = observer(({ menu }) => {
4468 return (
4569 < Navbar bg = "dark" variant = "dark" fixed = "top" expand = "lg" >
4670 < Container >
47- < Navbar . Brand href = "/" className = "fw-bolder" >
71+ < Navbar . Brand href = "/" className = "fw-bolder d-flex align-items-center gap-2" >
72+ < Image width = { 40 } src = { DefaultImage } alt = { t ( 'open_source_bazaar' ) } />
4873 { t ( 'open_source_bazaar' ) }
4974 </ Navbar . Brand >
5075 < Navbar . Toggle aria-controls = "navbarScroll" />
5176 < Navbar . Collapse id = "navbarScroll" >
5277 < Nav className = "me-auto my-2 my-lg-0" navbarScroll >
53- { menu . map ( ( { href, name } ) => (
54- < Nav . Link
55- key = { `${ href } -${ name } ` }
56- href = { href }
57- className = { pathname === `${ href } ` ? 'fw-bolder text-light' : '' }
58- >
59- { name }
60- </ Nav . Link >
61- ) ) }
78+ { menu . map ( ( { href, title, subs } ) =>
79+ subs ? (
80+ < NavDropdown key = { title } title = { title } >
81+ { subs . map ( ( { href, title } ) => (
82+ < NavDropdown . Item key = { href } href = { href } >
83+ { title }
84+ </ NavDropdown . Item >
85+ ) ) }
86+ </ NavDropdown >
87+ ) : (
88+ < Nav . Link
89+ key = { `${ href } -${ title } ` }
90+ href = { href }
91+ className = { pathname === `${ href } ` ? 'fw-bolder text-light' : '' }
92+ >
93+ { title }
94+ </ Nav . Link >
95+ ) ,
96+ ) }
6297 </ Nav >
6398
6499 < LanguageMenu />
0 commit comments