Files
Iris/src/js/components/Modal/Modal.js

165 lines
5.7 KiB
JavaScript
Raw Normal View History

2016-11-14 17:32:36 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as helpers from '../../helpers'
import Icon from '../Icon'
import AddToPlaylistModal from './AddToPlaylistModal'
2017-03-08 09:13:24 +13:00
import AddToQueueModal from './AddToQueueModal'
2016-11-14 17:32:36 +13:00
import CreatePlaylistModal from './CreatePlaylistModal'
import EditPlaylistModal from './EditPlaylistModal'
2017-01-30 16:59:37 +13:00
import EditRadioModal from './EditRadioModal'
2017-01-24 09:04:26 +13:00
import ImageZoomModal from './ImageZoomModal'
import KioskModeModal from './KioskModeModal'
2018-02-01 08:06:40 +13:00
import InitialSetupModal from './InitialSetupModal'
import AuthorizationModal_Send from './AuthorizationModal_Send'
import AuthorizationModal_Receive from './AuthorizationModal_Receive'
2016-11-14 17:32:36 +13:00
2017-08-03 16:42:54 +12:00
import * as coreActions from '../../services/core/actions'
2016-11-14 17:32:36 +13:00
import * as uiActions from '../../services/ui/actions'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
import * as pusherActions from '../../services/pusher/actions'
2016-11-14 17:32:36 +13:00
class Modal extends React.Component{
constructor(props){
super(props)
}
2017-10-10 13:05:28 +13:00
componentWillReceiveProps(nextProps){
if (nextProps.modal){
$('body').addClass('modal-open')
} else {
$('body').removeClass('modal-open')
}
}
2017-10-09 21:08:27 +13:00
toggleFullscreen(){
let app = document.documentElement
if (app.requestFullscreen){
app.requestFullscreen()
} else if (app.webkitRequestFullscreen){
app.webkitRequestFullscreen()
} else if (app.mozRequestFullScreen){
app.mozRequestFullScreen()
} else if (app.msRequestFullscreen){
app.msRequestFullscreen()
}
}
2016-11-14 17:32:36 +13:00
render(){
2017-10-09 21:08:27 +13:00
if (!this.props.modal){
return null;
}
var can_fullscreen = false;
if (this.props.modal.name == 'kiosk_mode'){
can_fullscreen = true;
}
2016-11-14 17:32:36 +13:00
return (
2017-01-24 09:04:26 +13:00
<div className={this.props.modal.name+" modal"}>
2017-10-09 21:08:27 +13:00
<div className="controls">
<div className="control close" onClick={e => this.props.uiActions.closeModal()}>
<Icon name="close" className="white" />
</div>
2016-11-14 17:32:36 +13:00
</div>
2017-10-09 21:08:27 +13:00
2016-11-14 17:32:36 +13:00
<div className="content">
2017-10-09 16:56:09 +13:00
{ this.props.modal.name == 'add_to_playlist' ? <AddToPlaylistModal
uiActions={this.props.uiActions}
coreActions={this.props.coreActions}
spotifyActions={this.props.spotifyActions}
mopidyActions={this.props.mopidyActions}
playlists={this.props.playlists}
tracks_uris={this.props.modal.data.tracks_uris}
spotify_library_playlists={this.props.spotify_library_playlists}
mopidy_library_playlists={this.props.mopidy_library_playlists}
processes={this.props.processes} /> : null }
{ this.props.modal.name == 'add_to_queue' ? <AddToQueueModal
uiActions={this.props.uiActions}
mopidyActions={this.props.mopidyActions} /> : null }
{ this.props.modal.name == 'create_playlist' ? <CreatePlaylistModal
uiActions={this.props.uiActions}
coreActions={this.props.coreActions} /> : null }
{ this.props.modal.name == 'edit_playlist' ? <EditPlaylistModal
uiActions={this.props.uiActions}
coreActions={this.props.coreActions}
data={this.props.modal.data} /> : null }
{ this.props.modal.name == 'send_authorization' ? <AuthorizationModal_Send
uiActions={this.props.uiActions}
pusherActions={this.props.pusherActions}
data={this.props.modal.data} /> : null }
{ this.props.modal.name == 'receive_authorization' ? <AuthorizationModal_Receive
uiActions={this.props.uiActions}
spotifyActions={this.props.spotifyActions}
data={this.props.modal.data} /> : null }
{ this.props.modal.name == 'edit_radio' ? <EditRadioModal
uiActions={this.props.uiActions}
pusherActions={this.props.pusherActions}
spotifyActions={this.props.spotifyActions}
data={this.props.modal.data}
radio={this.props.radio}
artists={this.props.artists}
tracks={this.props.tracks} /> : null }
{ this.props.modal.name == 'image_zoom' ? <ImageZoomModal
uiActions={this.props.uiActions}
data={this.props.modal.data} /> : null }
{ this.props.modal.name == 'kiosk_mode' ? <KioskModeModal
uiActions={this.props.uiActions}
data={this.props.modal.data}
current_track={this.props.current_track} /> : null }
2018-02-01 08:06:40 +13:00
{ this.props.modal.name == 'initial_setup' ? <InitialSetupModal
2017-10-09 16:56:09 +13:00
uiActions={this.props.uiActions}
2018-02-01 08:06:40 +13:00
pusherActions={this.props.pusherActions} /> : null }
2017-10-09 16:56:09 +13:00
2016-11-14 17:32:36 +13:00
</div>
</div>
);
}
}
const mapStateToProps = (state, ownProps) => {
return {
current_track: (state.core.current_track && state.core.tracks[state.core.current_track.uri] !== undefined ? state.core.tracks[state.core.current_track.uri] : null),
volume: state.mopidy.volume,
mute: state.mopidy.mute,
2016-11-14 17:32:36 +13:00
modal: state.ui.modal,
radio: state.core.radio,
tracks: state.core.tracks,
artists: state.core.artists,
playlists: state.core.playlists,
2016-11-14 17:32:36 +13:00
context_menu: state.ui.context_menu,
2017-08-22 08:38:03 +12:00
processes: state.ui.processes,
2017-10-09 16:56:09 +13:00
load_queue: state.ui.load_queue,
2016-11-14 17:32:36 +13:00
mopidy_connected: state.mopidy.connected,
spotify_authorized: state.spotify.authorization,
spotify_library_playlists: state.spotify.library_playlists,
mopidy_library_playlists: state.mopidy.library_playlists
2016-11-14 17:32:36 +13:00
}
}
const mapDispatchToProps = (dispatch) => {
return {
2017-08-03 16:42:54 +12:00
coreActions: bindActionCreators(coreActions, dispatch),
2016-11-14 17:32:36 +13:00
uiActions: bindActionCreators(uiActions, dispatch),
pusherActions: bindActionCreators(pusherActions, dispatch),
2016-11-14 17:32:36 +13:00
spotifyActions: bindActionCreators(spotifyActions, dispatch),
2017-10-09 21:08:27 +13:00
mopidyActions: bindActionCreators(mopidyActions, dispatch)
2016-11-14 17:32:36 +13:00
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Modal)