-
Notifications
You must be signed in to change notification settings - Fork 15
/
Sidebar.js
executable file
·69 lines (56 loc) · 1.49 KB
/
Sidebar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react'
import { connect } from 'react-redux'
import Link, { NavLink } from 'redux-first-router-link'
import styles from '../css/Sidebar'
const Sidebar = ({ path, dispatch }) => (
<div className={styles.sidebar}>
<h2>SEO-FRIENDLY LINKS</h2>
<NavLink to='/' exact activeClassName={styles.active}>
Home
</NavLink>
<NavLink
activeClassName={styles.active}
to={{ type: 'LIST', payload: { category: 'redux' } }}
>
Redux
</NavLink>
<Link
className={isActive(path, '/list/react')}
to={{ type: 'LIST', payload: { category: 'react' } }}
>
React
</Link>
<div style={{ height: 20 }} />
<h2>EVENT HANDLERS</h2>
<span
role='link'
tabIndex='0'
className={isActive(path, '/')}
onClick={() => dispatch({ type: 'HOME' })}
>
Home
</span>
<span
role='link'
tabIndex='0'
className={isActive(path, '/list/redux')}
onClick={() => dispatch({ type: 'LIST', payload: { category: 'redux' } })}
>
Redux
</span>
<span
role='link'
tabIndex='0'
className={isActive(path, '/list/react')}
onClick={() => dispatch({ type: 'LIST', payload: { category: 'react' } })}
>
React
</span>
</div>
)
const isActive = (actualPath, expectedPath) =>
actualPath === expectedPath ? styles.active : ''
const mapStateToProps = state => ({
path: state.location.pathname
})
export default connect(mapStateToProps)(Sidebar)