Sidebar.js
3.07 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import s from './Sidebar.module.scss';
import LinksGroup from './LinksGroup/LinksGroup';
import { openSidebar, closeSidebar, changeActiveSidebarItem } from '../../actions/navigation';
import isScreen from '../../core/screenHelper';
class Sidebar extends React.Component {
static propTypes = {
sidebarStatic: PropTypes.bool,
sidebarOpened: PropTypes.bool,
dispatch: PropTypes.func.isRequired,
activeItem: PropTypes.string,
location: PropTypes.shape({
pathname: PropTypes.string,
}).isRequired,
};
static defaultProps = {
sidebarStatic: false,
sidebarOpened: false,
activeItem: '',
};
constructor(props) {
super(props);
this.onMouseEnter = this.onMouseEnter.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
}
onMouseEnter() {
if (!this.props.sidebarStatic && (isScreen('lg') || isScreen('xl'))) {
const paths = this.props.location.pathname.split('/');
paths.pop();
this.props.dispatch(openSidebar());
this.props.dispatch(changeActiveSidebarItem(paths.join('/')));
}
}
onMouseLeave() {
if (!this.props.sidebarStatic && (isScreen('lg') || isScreen('xl'))) {
this.props.dispatch(closeSidebar());
this.props.dispatch(changeActiveSidebarItem(null));
}
}
render() {
return (
<nav
onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}
className={[s.root, this.props.sidebarStatic ? s.staticSidebar : '', !this.props.sidebarOpened ? s.sidebarClose : ''].join(' ')}
>
<header className={s.logo}>
<img src="/images/emergency.png" style={{width: '130px', padding: '7px'}} alt="Emergency Inc. logo"/>
</header>
<ul className={s.nav}>
<LinksGroup
onActiveSidebarItemChange={activeItem => this.props.dispatch(changeActiveSidebarItem(activeItem))}
activeItem={this.props.activeItem}
header="영상 분석"
isHeader
iconName="fas fa-camera"
link="/app/main"
index="main"
// childrenLinks={[
// {
// header: 'Phone', link: '/app/file/phone',
// },
// {
// header: 'RaspberryPi', link: '/app/file/raspberrypi',
// },
// ]}
/>
<LinksGroup
onActiveSidebarItemChange={activeItem => this.props.dispatch(changeActiveSidebarItem(activeItem))}
activeItem={this.props.activeItem}
header="사진 등록"
isHeader
iconName="fas fa-user"
link="/app/subject"
index="subject"
/>
</ul>
</nav >
);
}
}
function mapStateToProps(store) {
return {
sidebarOpened: store.navigation.sidebarOpened,
sidebarStatic: store.navigation.sidebarStatic,
activeItem: store.navigation.activeItem,
};
}
export default withRouter(connect(mapStateToProps)(Sidebar));