added redux to metadata inputs
This commit is contained in:
parent
325cb03661
commit
02161aa85c
4 changed files with 52 additions and 34 deletions
|
@ -63,9 +63,9 @@ class PublishForm extends React.Component {
|
||||||
<ChannelSelector />
|
<ChannelSelector />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<PublishMetadataInputs
|
<div className="row row--padded row--no-top row--no-bottom row--wide">
|
||||||
updateUploaderState={this.props.updateUploaderState}
|
<PublishMetadataInputs />
|
||||||
/>
|
</div>
|
||||||
|
|
||||||
<div className="row row--padded row--wide">
|
<div className="row row--padded row--wide">
|
||||||
<div className="input-error" id="input-error-publish-submit" hidden="true">{this.state.error}</div>
|
<div className="input-error" id="input-error-publish-submit" hidden="true">{this.state.error}</div>
|
||||||
|
@ -89,12 +89,9 @@ class PublishForm extends React.Component {
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
return {
|
return {
|
||||||
fileType : state.file.type,
|
fileType : state.file.type,
|
||||||
claim : state.claim,
|
claim : state.claim,
|
||||||
thumbnail : state.thumbnail,
|
thumbnail: state.thumbnail,
|
||||||
description: state.description,
|
|
||||||
license : state.license,
|
|
||||||
nsfw : state.nsfw,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,45 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import { updateMetadata } from '../actions';
|
||||||
|
|
||||||
class MetadataInputs extends React.Component {
|
class MetadataInputs extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
showInputs : false,
|
showInputs: false,
|
||||||
};
|
};
|
||||||
this.toggleShowInputs = this.toggleShowInputs.bind(this);
|
this.toggleShowInputs = this.toggleShowInputs.bind(this);
|
||||||
this.handleInput = this.handleInput.bind(this);
|
this.handleInput = this.handleInput.bind(this);
|
||||||
|
this.handleCheck = this.handleCheck.bind(this);
|
||||||
this.handleSelection = this.handleSelection.bind(this);
|
this.handleSelection = this.handleSelection.bind(this);
|
||||||
}
|
}
|
||||||
toggleShowInputs () {
|
toggleShowInputs () {
|
||||||
if (this.state.showInputs) {
|
this.setState({'showInputs': !this.state.showInputs});
|
||||||
this.setState({'showInputs': false});
|
|
||||||
} else {
|
|
||||||
this.setState({'showInputs': true});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
handleInput (event) {
|
handleInput (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const target = event.target;
|
const name = event.target.name;
|
||||||
const name = target.name;
|
const value = event.target.value;
|
||||||
const value = target.type === 'checkbox' ? target.checked : target.value;
|
this.props.onMetadataChange(name, value);
|
||||||
this.props.updateUploaderState(name, value);
|
}
|
||||||
|
handleCheck (event) {
|
||||||
|
console.log('handle input', event);
|
||||||
|
event.preventDefault();
|
||||||
|
const name = event.target.name;
|
||||||
|
const value = event.target.checked;
|
||||||
|
this.props.onMetadataChange(name, value);
|
||||||
}
|
}
|
||||||
handleSelection (event) {
|
handleSelection (event) {
|
||||||
|
const name = event.target.name;
|
||||||
const selectedOption = event.target.selectedOptions[0].value;
|
const selectedOption = event.target.selectedOptions[0].value;
|
||||||
this.props.updateUploaderState('', value);
|
this.props.onMetadataChange(name, selectedOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="row row--padded row--no-top row--no-bottom row--wide">
|
<div className="column column--10">
|
||||||
<div className="column column--10">
|
<a className="label link--primary" id="publish-details-toggle" href="#" onClick={this.toggleShowInputs}>{this.state.showInputs ? '[less]' : '[more]'}</a>
|
||||||
<a className="label link--primary" id="publish-details-toggle" href="#" onClick={this.toggleShowInputs}>{this.state.showInputs ? '[less]' : '[more]'}</a>
|
</div>
|
||||||
</div>
|
|
||||||
{this.state.showInputs && (
|
{this.state.showInputs && (
|
||||||
<div id="publish-details" className="row row--padded row--wide">
|
<div id="publish-details" className="row row--padded row--wide">
|
||||||
|
|
||||||
|
@ -51,7 +55,7 @@ class MetadataInputs extends React.Component {
|
||||||
<div className="column column--3 column--med-10">
|
<div className="column column--3 column--med-10">
|
||||||
<label htmlFor="publish-license" className="label">License:</label>
|
<label htmlFor="publish-license" className="label">License:</label>
|
||||||
</div><div className="column column--7 column--sml-10">
|
</div><div className="column column--7 column--sml-10">
|
||||||
<select type="text" name="license" id="publish-license" className="select select--primary" onSelect={this.handleSelection}>
|
<select type="text" name="license" id="publish-license" className="select select--primary" onChange={this.handleSelection}>
|
||||||
<option value=" ">Unspecified</option>
|
<option value=" ">Unspecified</option>
|
||||||
<option value="Public Domain">Public Domain</option>
|
<option value="Public Domain">Public Domain</option>
|
||||||
<option value="Creative Commons">Creative Commons</option>
|
<option value="Creative Commons">Creative Commons</option>
|
||||||
|
@ -63,16 +67,30 @@ class MetadataInputs extends React.Component {
|
||||||
<div className="column column--3">
|
<div className="column column--3">
|
||||||
<label htmlFor="publish-nsfw" className="label">Mature:</label>
|
<label htmlFor="publish-nsfw" className="label">Mature:</label>
|
||||||
</div><div className="column column--7">
|
</div><div className="column column--7">
|
||||||
<input className="input-checkbox" type="checkbox" id="publish-nsfw" name="nsfw" checked={this.props.nsfw} onChange={this.handleInput} />
|
<input className="input-checkbox" type="checkbox" id="publish-nsfw" name="nsfw" checked={this.props.nsfw} onChange={this.handleCheck} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MetadataInputs;
|
const mapStateToProps = state => {
|
||||||
|
return {
|
||||||
|
description: state.metadata.description,
|
||||||
|
license : state.metadata.license,
|
||||||
|
nsfw : state.metadata.nsfw,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
onMetadataChange: (name, value) => {
|
||||||
|
dispatch(updateMetadata(name, value));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(MetadataInputs);
|
||||||
|
|
|
@ -5,7 +5,10 @@ import { createStore } from 'redux';
|
||||||
import Reducers from './reducers/index.js';
|
import Reducers from './reducers/index.js';
|
||||||
import PublishTool from './components/PublishTool.jsx';
|
import PublishTool from './components/PublishTool.jsx';
|
||||||
|
|
||||||
let store = createStore(Reducers)
|
let store = createStore(
|
||||||
|
Reducers,
|
||||||
|
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
|
||||||
|
);
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
|
|
|
@ -19,7 +19,7 @@ const initialState = {
|
||||||
thumbnail : '',
|
thumbnail : '',
|
||||||
description: '',
|
description: '',
|
||||||
license : '',
|
license : '',
|
||||||
nsfw : '',
|
nsfw : false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ export default function (state = initialState, action) {
|
||||||
case METADATA_UPDATE:
|
case METADATA_UPDATE:
|
||||||
console.log(`reducer for ${action.name} ${action.value}`);
|
console.log(`reducer for ${action.name} ${action.value}`);
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
metadata: {
|
metadata: Object.assign({}, state.metadata, {
|
||||||
[action.name]: action.value,
|
[action.name]: action.value,
|
||||||
},
|
}),
|
||||||
});
|
});
|
||||||
case CLAIM_UPDATE:
|
case CLAIM_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
|
Loading…
Reference in a new issue