6
6
7
7
import React from 'react'
8
8
import Link from 'next/link'
9
+ // import Router, { withRouter } from 'next/router'
9
10
import R from 'ramda'
10
11
import { inject , observer } from 'mobx-react'
11
12
12
13
import * as SuggestionIcons from '../../containers/Doraemon/styles/suggestionIcons'
13
- // import { makeDebugger } from '../../utils/functions'
14
14
15
15
import { makeDebugger , storeSelector } from '../../utils/functions'
16
16
import PinButton from './PinButton'
@@ -24,26 +24,29 @@ const DefaultIcon = SuggestionIcons.javascript
24
24
25
25
const getIconKey = R . compose ( R . last , R . split ( '--' ) , R . toLower )
26
26
27
- const NodeIcon = ( { raw} ) => {
27
+ const NodeIcon = ( { raw, active } ) => {
28
28
const lowerRaw = R . toLower ( raw )
29
29
const iconKey = getIconKey ( lowerRaw )
30
30
31
31
const Icon = Icons [ iconKey ] ?Icons [ iconKey ] :DefaultIcon
32
32
return (
33
- < SVGIconWrapper >
33
+ < SVGIconWrapper active = { active } >
34
34
< Icon />
35
35
</ SVGIconWrapper >
36
36
)
37
37
}
38
38
39
- const MenuList = ( { items, open} ) => {
39
+ const MenuList = ( { items, open, curUrlPath } ) => {
40
40
const listItems = items . map ( item => (
41
41
< li key = { item . name } >
42
42
{ open ?(
43
43
< div >
44
44
< 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
+ />
47
50
{ /* eslint-disable jsx-a11y/anchor-is-valid */ }
48
51
< div style = { { marginRight :10 } } />
49
52
< a > { item . name } </ a >
@@ -52,7 +55,10 @@ const MenuList = ({ items, open }) => {
52
55
</ div >
53
56
) :(
54
57
< Row >
55
- < NodeIcon raw = { item . name } />
58
+ < NodeIcon
59
+ raw = { item . name }
60
+ active = { curUrlPath === R . toLower ( item . name ) }
61
+ />
56
62
</ Row >
57
63
) }
58
64
</ li >
@@ -68,19 +74,20 @@ class SidebarContainer extends React.Component {
68
74
69
75
render ( ) {
70
76
const { sidebar} = this . props
71
- /* debug('-----> menuItems2 --------> : ', sidebar.menuItems.toJSON()) */
77
+ const { curUrlPath, menuItems, open, pin} = sidebar
78
+ // debug('-----> sidebar route --------> : ', this.props.router)
72
79
73
80
return (
74
81
< Sidebar
75
82
open = { sidebar . open }
76
83
onMouseEnter = { logic . enterSidebar }
77
84
onMouseLeave = { logic . leaveSidebar }
78
85
>
79
- < PinButton open = { sidebar . open } pin = { sidebar . pin } onClick = { logic . pin } />
86
+ < PinButton open = { open } pin = { pin } onClick = { logic . pin } />
80
87
< br />
81
88
< br />
82
89
83
- < MenuList items = { sidebar . menuItems } open = { sidebar . open } />
90
+ < MenuList items = { menuItems } open = { open } curUrlPath = { curUrlPath } />
84
91
</ Sidebar >
85
92
)
86
93
}