66
77import React from 'react'
88import Link from 'next/link'
9+ // import Router, { withRouter } from 'next/router'
910import R from 'ramda'
1011import { inject , observer } from 'mobx-react'
1112
1213import * as SuggestionIcons from '../../containers/Doraemon/styles/suggestionIcons'
13- // import { makeDebugger } from '../../utils/functions'
1414
1515import { makeDebugger , storeSelector } from '../../utils/functions'
1616import PinButton from './PinButton'
@@ -24,26 +24,29 @@ const DefaultIcon = SuggestionIcons.javascript
2424
2525const getIconKey = R . compose ( R . last , R . split ( '--' ) , R . toLower )
2626
27- const NodeIcon = ( { raw } ) => {
27+ const NodeIcon = ( { raw, active } ) => {
2828 const lowerRaw = R . toLower ( raw )
2929 const iconKey = getIconKey ( lowerRaw )
3030
3131 const Icon = Icons [ iconKey ] ? Icons [ iconKey ] : DefaultIcon
3232 return (
33- < SVGIconWrapper >
33+ < SVGIconWrapper active = { active } >
3434 < Icon />
3535 </ SVGIconWrapper >
3636 )
3737}
3838
39- const MenuList = ( { items, open } ) => {
39+ const MenuList = ( { items, open, curUrlPath } ) => {
4040 const listItems = items . map ( item => (
4141 < li key = { item . name } >
4242 { open ? (
4343 < div >
4444 < Link href = { item . target . href } as = { item . target . as } >
45- < Row >
46- < NodeIcon raw = { item . name } />
45+ < Row active = { curUrlPath === R . toLower ( item . name ) } >
46+ < NodeIcon
47+ raw = { item . name }
48+ active = { curUrlPath === R . toLower ( item . name ) }
49+ />
4750 { /* eslint-disable jsx-a11y/anchor-is-valid */ }
4851 < div style = { { marginRight : 10 } } />
4952 < a > { item . name } </ a >
@@ -52,7 +55,10 @@ const MenuList = ({ items, open }) => {
5255 </ div >
5356 ) : (
5457 < Row >
55- < NodeIcon raw = { item . name } />
58+ < NodeIcon
59+ raw = { item . name }
60+ active = { curUrlPath === R . toLower ( item . name ) }
61+ />
5662 </ Row >
5763 ) }
5864 </ li >
@@ -68,19 +74,20 @@ class SidebarContainer extends React.Component {
6874
6975 render ( ) {
7076 const { sidebar } = this . props
71- /* debug('-----> menuItems2 --------> : ', sidebar.menuItems.toJSON()) */
77+ const { curUrlPath, menuItems, open, pin } = sidebar
78+ // debug('-----> sidebar route --------> : ', this.props.router)
7279
7380 return (
7481 < Sidebar
7582 open = { sidebar . open }
7683 onMouseEnter = { logic . enterSidebar }
7784 onMouseLeave = { logic . leaveSidebar }
7885 >
79- < PinButton open = { sidebar . open } pin = { sidebar . pin } onClick = { logic . pin } />
86+ < PinButton open = { open } pin = { pin } onClick = { logic . pin } />
8087 < br />
8188 < br />
8289
83- < MenuList items = { sidebar . menuItems } open = { sidebar . open } />
90+ < MenuList items = { menuItems } open = { open } curUrlPath = { curUrlPath } />
8491 </ Sidebar >
8592 )
8693 }
0 commit comments