Search settings; Search action now uiAction

This commit is contained in:
James Barnsley
2017-03-24 08:46:20 +13:00
parent 0db7a92130
commit 6bf4a71bf2
9 changed files with 149 additions and 81 deletions

View File

@ -60,7 +60,7 @@ export default class DropdownField extends React.Component{
return (
<div className={classname} data-key={this.props.name.replace(' ','_').toLowerCase()}>
<div className="label" onClick={ () => this.handleToggle() }>
{this.props.icon ? <span><FontAwesome name={this.props.icon} />&nbsp;</span> : null}
{this.props.icon ? <span><FontAwesome name={this.props.icon} />&nbsp; </span> : null}
<span className="text">{ this.props.name }</span>
</div>
<div className="options">

View File

@ -13,6 +13,7 @@ import SendAuthorizationModal from './SendAuthorizationModal'
import EditRadioModal from './EditRadioModal'
import ImageZoomModal from './ImageZoomModal'
import KioskModeModal from './KioskModeModal'
import SearchSettingsModal from './SearchSettingsModal'
import * as uiActions from '../../services/ui/actions'
import * as mopidyActions from '../../services/mopidy/actions'
@ -51,6 +52,7 @@ class Modal extends React.Component{
{ 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} /> : null }
{ this.props.modal.name == 'search_settings' ? <SearchSettingsModal uiActions={this.props.uiActions} search_settings={this.props.search_settings} uri_schemes={this.props.uri_schemes} data={this.props.modal.data} /> : null }
</div>
</div>
@ -60,6 +62,8 @@ class Modal extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
uri_schemes: (state.mopidy.uri_schemes ? state.mopidy.uri_schemes : null),
search_settings: (state.ui.search_settings ? state.ui.search_settings : null),
modal: state.ui.modal,
radio: state.ui.radio,
tracks: state.ui.tracks,

View File

@ -0,0 +1,90 @@
import React, { PropTypes } from 'react'
import FontAwesome from 'react-fontawesome'
import Icon from '../Icon'
import * as helpers from '../../helpers'
export default class SearchSettingsModal extends React.Component{
constructor(props){
super(props)
this.state = {
spotify: true,
uri_schemes: []
}
}
componentDidMount(){
if (this.props.search_settings){
this.setState(this.props.search_settings)
} else {
this.setState({
spotify: true,
uri_schemes: this.props.uri_schemes
})
}
}
handleSubmit(e){
this.props.uiActions.set({search_settings: this.state})
this.props.uiActions.closeModal()
this.props.uiActions.startSearch(this.props.data.type, this.props.data.query)
}
handleToggle(scheme){
var uri_schemes = this.state.uri_schemes
var index = uri_schemes.indexOf(scheme)
if (index > -1){
uri_schemes.splice(index,1)
} else {
uri_schemes.push(scheme)
}
this.setState({uri_schemes: uri_schemes})
}
render(){
return (
<div>
<h4 className="no-bottom-padding">Advanced search settings</h4>
<h3 className="grey-text bottom-padding">Customise the providers used when searching</h3>
<form onSubmit={e => this.handleSubmit(e)}>
<div className="field checkbox white">
<label>
<input
type="checkbox"
name="enabled"
checked={ this.state.spotify }
onChange={ e => this.setState({ spotify: !this.state.spotify })} />
<span className="label">spotify <span className="grey-text">(http)</span></span>
</label>
</div>
{
this.props.uri_schemes.map(scheme => {
return (
<div className="field checkbox white" key={scheme}>
<label>
<input
type="checkbox"
name={scheme}
checked={this.state.uri_schemes.indexOf(scheme) > -1}
onChange={ e => this.handleToggle(scheme)} />
<span className="label">{scheme.replace(':','')} <span className="grey-text">(mopidy)</span></span>
</label>
</div>
)
})
}
<div className="actions centered-text">
<button type="submit" className="primary wide">Save</button>
</div>
</form>
</div>
)
}
}

View File

@ -7,7 +7,6 @@ import FontAwesome from 'react-fontawesome'
import * as helpers from '../helpers'
import * as uiActions from '../services/ui/actions'
import * as spotifyActions from '../services/spotify/actions'
class SearchForm extends React.Component{
@ -38,7 +37,7 @@ class SearchForm extends React.Component{
break
default:
hashHistory.push(global.baseURL+'search/'+this.state.query)
hashHistory.push(global.baseURL+'search/all/'+this.state.query)
break
}
@ -58,15 +57,10 @@ class SearchForm extends React.Component{
}
}
const mapStateToProps = (state, ownProps) => {
return state;
}
const mapDispatchToProps = (dispatch) => {
return {
uiActions: bindActionCreators(uiActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
uiActions: bindActionCreators(uiActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(SearchForm)
export default connect(mapDispatchToProps)(SearchForm)