forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
310 lines (285 loc) · 8.81 KB
/
App.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import React from 'react';
import FontAwesome from 'react-fontawesome';
import Sound from 'react-sound';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { NavLink, Link, withRouter } from 'react-router-dom';
import classnames from 'classnames';
import _ from 'lodash';
import * as Actions from './actions';
import * as PlayerActions from './actions/player';
import * as PluginsActions from './actions/plugins';
import * as QueueActions from './actions/queue';
import * as SettingsActions from './actions/settings';
import * as ScrobblingActions from './actions/scrobbling';
import './app.global.scss';
import styles from './styles.scss';
import compact from './compact.scss';
import logoImg from '../resources/media/logo_full_light.png';
import logoIcon from '../resources/media/512x512.png';
import artPlaceholder from '../resources/media/art_placeholder.png';
import { config as PluginConfig } from './plugins/config';
import settingsConst from './constants/settings';
import Footer from './components/Footer';
import Navbar from './components/Navbar';
import VerticalPanel from './components/VerticalPanel';
import Spacer from './components/Spacer';
import MainContentContainer from './containers/MainContentContainer';
import PlayQueueContainer from './containers/PlayQueueContainer';
import SearchBoxContainer from './containers/SearchBoxContainer';
import IpcContainer from './containers/IpcContainer';
import SoundContainer from './containers/SoundContainer';
import ui from 'nuclear-ui';
import PlayerControls from './components/PlayerControls';
import Seekbar from './components/Seekbar';
import SidebarMenu from './components/SidebarMenu';
import SidebarMenuItem from './components/SidebarMenu/SidebarMenuItem';
import TrackInfo from './components/TrackInfo';
import WindowControls from './components/WindowControls';
import VolumeControls from './components/VolumeControls';
class App extends React.Component {
togglePlayback () {
if (
this.props.player.playbackStatus === Sound.status.PAUSED &&
this.props.scrobbling.lastFmScrobblingEnabled &&
this.props.scrobbling.lastFmSessionKey
) {
let currentSong = this.props.queue.queueItems[
this.props.queue.currentSong
];
this.props.actions.updateNowPlayingAction(
currentSong.artist,
currentSong.name,
this.props.scrobbling.lastFmSessionKey
);
}
this.props.actions.togglePlayback(this.props.player.playbackStatus);
}
nextSong () {
this.props.actions.nextSong();
if (
this.props.scrobbling.lastFmScrobblingEnabled &&
this.props.scrobbling.lastFmSessionKey
) {
let currentSong = this.props.queue.queueItems[
this.props.queue.currentSong
];
this.props.actions.updateNowPlayingAction(
currentSong.artist,
currentSong.name,
this.props.scrobbling.lastFmSessionKey
);
}
}
renderNavBar () {
return (
<Navbar className={styles.navbar}>
<SearchBoxContainer />
<Spacer />
<Spacer />
{this.props.settings.framelessWindow && <WindowControls />}
</Navbar>
);
}
renderRightPanel (settings) {
return (
<VerticalPanel
className={classnames(styles.right_panel, {
[`${compact.compact_panel}`]: settings.compactQueueBar
})}
>
<PlayQueueContainer compact={settings.compactQueueBar} />
</VerticalPanel>
);
}
renderSidebarMenu (settings, toggleOption) {
return (
<VerticalPanel
className={classnames(styles.left_panel, {
[`${compact.compact_panel}`]: settings.compactMenuBar
})}
>
<SidebarMenu>
<div className={styles.sidebar_brand}>
<img
width='50%'
src={settings.compactMenuBar ? logoIcon : logoImg}
/>
<div className={styles.version_string}>
{settings.compactMenuBar ? '0.4.4' : 'Version 0.4.4'}
</div>
</div>
{this.renderNavLink('dashboard', 'dashboard', 'Dashboard', settings)}
{this.renderNavLink('downloads', 'download', 'Downloads', settings)}
{this.renderNavLink('playlists', 'music', 'Playlists', settings)}
{this.renderNavLink('plugins', 'flask', 'Plugins', settings)}
{this.renderNavLink('settings', 'cogs', 'Settings', settings)}
{this.renderNavLink('search', 'search', 'Search Results', settings)}
<Spacer />
{this.renderSidebarFooter(settings, toggleOption)}
</SidebarMenu>
</VerticalPanel>
);
}
renderNavLink (name, icon, prettyName, settings) {
return (
<NavLink to={'/' + name} activeClassName={styles.active_nav_link}>
<SidebarMenuItem>
<FontAwesome name={icon} /> {!settings.compactMenuBar && prettyName}
</SidebarMenuItem>
</NavLink>
);
}
renderSidebarFooter (settings, toggleOption) {
return (
<div className='sidebar_footer'>
<a
onClick={() =>
toggleOption(
_.find(settingsConst, ['name', 'compactMenuBar']),
settings
)
}
href='#'
>
<FontAwesome
name={settings.compactMenuBar ? 'angle-right' : 'angle-left'}
/>
</a>
</div>
);
}
renderFooter (settings) {
return (
<Footer className={styles.footer}>
<Seekbar
fill={this.props.player.playbackProgress + '%'}
seek={this.props.actions.updateSeek}
queue={this.props.queue}
/>
<div className={styles.footer_horizontal}>
<div className={styles.track_info_wrapper}>
{this.renderCover()}
{this.renderTrackInfo()}
</div>
{this.renderPlayerControls()}
{this.renderVolumeControl(settings)}
</div>
</Footer>
);
}
renderCover () {
return (
<ui.Cover
cover={
this.props.queue.queueItems[this.props.queue.currentSong]
? this.props.queue.queueItems[this.props.queue.currentSong]
.thumbnail
: artPlaceholder
}
/>
);
}
getCurrentSongParameter (parameter) {
return this.props.queue.queueItems[this.props.queue.currentSong]
? this.props.queue.queueItems[this.props.queue.currentSong][parameter]
: null;
}
renderTrackInfo () {
return (
<TrackInfo
track={this.getCurrentSongParameter('name')}
artist={this.getCurrentSongParameter('artist')}
artistInfoSearchByName={this.props.actions.artistInfoSearchByName}
history={this.props.history}
/>
);
}
renderPlayerControls () {
return (
<PlayerControls
togglePlay={this.togglePlayback.bind(this)}
playing={this.props.player.playbackStatus === Sound.status.PLAYING}
loading={this.props.player.playbackStreamLoading}
forward={this.nextSong.bind(this)}
back={this.props.actions.previousSong}
/>
);
}
renderVolumeControl (settings) {
return (
<VolumeControls
fill={this.props.player.volume}
updateVolume={this.props.actions.updateVolume}
muted={this.props.player.muted}
toggleMute={this.props.actions.toggleMute}
toggleOption={this.props.actions.toggleOption}
settings={settings}
/>
);
}
renderNavbar () {
return (
<Navbar className={styles.navbar}>
<SearchBoxContainer />
<Spacer />
<Spacer />
<WindowControls />
</Navbar>
);
}
componentWillMount () {
this.props.actions.readSettings();
this.props.actions.lastFmReadSettings();
this.props.actions.createSearchPlugins(PluginConfig.plugins);
}
render () {
let { settings } = this.props;
let { toggleOption } = this.props.actions;
return (
<div className={styles.app_container}>
{this.renderNavBar()}
<div className={styles.panel_container}>
{this.renderSidebarMenu(settings, toggleOption)}
<VerticalPanel className={styles.center_panel}>
<MainContentContainer />
</VerticalPanel>
{this.renderRightPanel(settings)}
</div>
{this.renderFooter(settings)}
<SoundContainer />
<IpcContainer />
</div>
);
}
}
function mapStateToProps (state) {
return {
queue: state.queue,
player: state.player,
scrobbling: state.scrobbling,
settings: state.settings
};
}
function mapDispatchToProps (dispatch) {
return {
actions: bindActionCreators(
Object.assign(
{},
ScrobblingActions,
SettingsActions,
QueueActions,
PlayerActions,
PluginsActions,
Actions
),
dispatch
)
};
}
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(App)
);