-
Notifications
You must be signed in to change notification settings - Fork 8
/
Sidebar.js
executable file
·81 lines (68 loc) · 1.76 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
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react'
import { connect } from 'react-redux'
import { NavLink, Link } from '@respond-framework/react'
import styles from '../css/Sidebar'
// TODO: Use the link package
/* eslint-disable jsx-a11y/click-events-have-key-events */
// TODO: fix NavLink when object is passed via the "to" prop
const Sidebar = ({ path, dispatch }) => (
<div className={styles.sidebar}>
<h2>SEO-FRIENDLY LINKS</h2>
<NavLink to="/" activeClassName={styles.active}>
Home
</NavLink>
<Link
role="link"
tabIndex="0"
to={{ type: 'LIST', params: { category: 'redux' } }}
>
Redux
</Link>
<span
role="link"
tabIndex="0"
onClick={() => dispatch({ type: 'LIST', params: { category: 'react' } })}
>
React
</span>
<span
role="link"
tabIndex="0"
onClick={() => dispatch({ type: 'NOT_FOUND' })}
>
NOT_FOUND
</span>
<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', params: { category: 'redux' } })}
>
Redux
</span>
<span
role="link"
tabIndex="0"
className={isActive(path, '/list/react')}
onClick={() => dispatch({ type: 'LIST', params: { 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)