/
topBar.js
175 lines (152 loc) · 4.81 KB
/
topBar.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import React from 'react';
import routes from '../../constants/routes';
import MenuItems from './menuItems';
import UserAccount from './accountMenu/userAccount';
import NavigationButtons from './navigationButtons';
import Piwik from '../../utils/piwik';
import menuLinks from './constants';
import Dropdown from '../toolbox/dropdown/dropdown';
import SearchBar from '../searchBar';
import Network from './network';
import networks from '../../constants/networks';
import styles from './topBar.css';
import OutsideClickHandler from '../toolbox/outsideClickHandler';
import Icon from '../toolbox/icon';
import Autologout from './autologout/autologout';
class TopBar extends React.Component {
constructor(props) {
super(props);
this.state = {
openDropdown: '',
};
this.searchInput = null;
this.onLogout = this.onLogout.bind(this);
this.handleSearchDropdown = this.onHandleClick.bind(this, 'search');
this.handleAccountDropdown = this.onHandleClick.bind(this, 'account');
this.onCountdownComplete = this.onCountdownComplete.bind(this);
}
onLogout() {
const {
logOut, history, settings, networkSet, network,
} = this.props;
Piwik.trackingEvent('Header', 'button', 'Open logout dialog');
logOut();
history.replace(`${routes.dashboard.path}`);
if (!settings.showNetwork && network.name !== networks.mainnet.name) {
networkSet(networks.mainnet);
}
}
onHandleClick(name) {
const { openDropdown } = this.state;
if (name === 'search' && openDropdown !== name) {
setTimeout(() => this.searchInput.focus(), 150);
}
this.setState({
openDropdown: openDropdown === name ? '' : name,
});
}
/* istanbul ignore next */
onCountdownComplete() {
this.props.logOut();
this.props.history.replace(routes.login.path);
}
/* istanbul ignore next */
isTimerEnabled() {
const { autoLogout, account } = this.props;
return autoLogout
&& account.expireTime
&& account.expireTime !== 0
&& account.passphrase
&& account.passphrase.length > 0;
}
render() {
const {
t,
account,
history,
network,
token,
settingsUpdated,
resetTimer,
} = this.props;
const { openDropdown } = this.state;
const items = menuLinks(t);
const isUserLogout = !!(Object.keys(account).length === 0 || account.afterLogout);
return (
<div className={`${styles.wrapper} top-bar`}>
<div>
<div className={styles.logo}>
<Icon name="liskLogo" className="topbar-logo" />
</div>
<NavigationButtons
account={account}
history={history}
/>
<MenuItems
token={token}
isUserLogout={isUserLogout}
items={items}
location={this.props.location}
/>
</div>
<div>
<Network
token={token.active}
network={network}
t={t}
/>
{this.isTimerEnabled() ? (
<div className={styles.timer}>
<Autologout
onCountdownComplete={this.onCountdownComplete}
account={account}
history={history}
resetTimer={resetTimer}
t={t}
/>
</div>
) : null}
<UserAccount
token={token}
className={styles.userAccount}
account={account}
isDropdownEnable={openDropdown === 'account'}
onDropdownToggle={this.handleAccountDropdown}
onLogout={this.onLogout}
settingsUpdated={settingsUpdated}
isUserLogout={isUserLogout}
t={t}
/>
{token.active !== 'BTC'
? (
<OutsideClickHandler
className={`${styles.searchButton} search-section`}
onOutsideClick={this.handleSearchDropdown}
disabled={openDropdown !== 'search'}
wrapper={<label />}
>
<Icon
onClick={this.handleSearchDropdown}
className="search-icon"
name={`search_icon_${openDropdown === 'search' ? 'active' : 'inactive'}`}
/>
<Dropdown
showDropdown={openDropdown === 'search'}
className={`${styles.searchDropdown}`}
showArrow={false}
>
<SearchBar
setSearchBarRef={(node) => { this.searchInput = node; }}
history={this.props.history}
onSearchClick={this.handleSearchDropdown}
/>
</Dropdown>
</OutsideClickHandler>
)
: null }
</div>
</div>
);
}
}
export default TopBar;