React/Redux - publish component #323

Merged
bones7242 merged 80 commits from react-upload into master 2018-01-25 22:43:20 +01:00
4 changed files with 52 additions and 34 deletions
Showing only changes of commit 02161aa85c - Show all commits

View file

@ -63,9 +63,9 @@ class PublishForm extends React.Component {
<ChannelSelector />
</div>
<PublishMetadataInputs
updateUploaderState={this.props.updateUploaderState}
/>
<div className="row row--padded row--no-top row--no-bottom row--wide">
<PublishMetadataInputs />
</div>
<div className="row row--padded row--wide">
<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 => {
return {
fileType : state.file.type,
claim : state.claim,
thumbnail : state.thumbnail,
description: state.description,
license : state.license,
nsfw : state.nsfw,
fileType : state.file.type,
claim : state.claim,
thumbnail: state.thumbnail,
};
};

View file

@ -1,41 +1,45 @@
import React from 'react';
import { connect } from 'react-redux';
import { updateMetadata } from '../actions';
class MetadataInputs extends React.Component {
constructor (props) {
super(props);
this.state = {
showInputs : false,
showInputs: false,
};
this.toggleShowInputs = this.toggleShowInputs.bind(this);
this.handleInput = this.handleInput.bind(this);
this.handleCheck = this.handleCheck.bind(this);
this.handleSelection = this.handleSelection.bind(this);
}
toggleShowInputs () {
if (this.state.showInputs) {
this.setState({'showInputs': false});
} else {
this.setState({'showInputs': true});
}
this.setState({'showInputs': !this.state.showInputs});
}
handleInput (event) {
event.preventDefault();
const target = event.target;
const name = target.name;
const value = target.type === 'checkbox' ? target.checked : target.value;
this.props.updateUploaderState(name, value);
const name = event.target.name;
const value = event.target.value;
this.props.onMetadataChange(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) {
const name = event.target.name;
const selectedOption = event.target.selectedOptions[0].value;
this.props.updateUploaderState('', value);
this.props.onMetadataChange(name, selectedOption);
}
render () {
return (
<div>
<div className="row row--padded row--no-top row--no-bottom row--wide">
<div className="column column--10">
<a className="label link--primary" id="publish-details-toggle" href="#" onClick={this.toggleShowInputs}>{this.state.showInputs ? '[less]' : '[more]'}</a>
</div>
<div className="column column--10">
<a className="label link--primary" id="publish-details-toggle" href="#" onClick={this.toggleShowInputs}>{this.state.showInputs ? '[less]' : '[more]'}</a>
</div>
{this.state.showInputs && (
<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">
<label htmlFor="publish-license" className="label">License:</label>
</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="Public Domain">Public Domain</option>
<option value="Creative Commons">Creative Commons</option>
@ -63,16 +67,30 @@ class MetadataInputs extends React.Component {
<div className="column column--3">
<label htmlFor="publish-nsfw" className="label">Mature:</label>
</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>
);
}
}
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);

View file

@ -5,7 +5,10 @@ import { createStore } from 'redux';
import Reducers from './reducers/index.js';
import PublishTool from './components/PublishTool.jsx';
let store = createStore(Reducers)
let store = createStore(
Reducers,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
ReactDOM.render(
<Provider store={store}>

View file

@ -19,7 +19,7 @@ const initialState = {
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
thumbnail : '',
description: '',
license : '',
nsfw : '',
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
nsfw : false,
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
},
};
@ -38,9 +38,9 @@ export default function (state = initialState, action) {
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
case METADATA_UPDATE:
console.log(`reducer for ${action.name} ${action.value}`);
return Object.assign({}, state, {
metadata: {
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
metadata: Object.assign({}, state.metadata, {
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
[action.name]: action.value,
},
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
}),
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
});
case CLAIM_UPDATE:
return Object.assign({}, state, {

kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).
kauffj commented 2018-01-15 20:27:22 +01:00 (Migrated from github.com)
Review

import * as

`import * as`
kauffj commented 2018-01-15 20:28:40 +01:00 (Migrated from github.com)
Review

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).

Some of these should possibly be renamed or refactored into separate files (or possibly can wait until next refactor/revision).