From 6a8a908130b3225423e306bac414ffb1740531e5 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 24 Jan 2018 12:32:24 -0800 Subject: [PATCH] added check to make sure channel is selcted if not publishing anonymously --- react/containers/ChannelSelect/index.js | 1 + react/containers/ChannelSelect/view.jsx | 2 +- react/containers/PublishForm/index.js | 4 ++++ react/containers/PublishForm/view.jsx | 28 ++++++++++++++++++------- react/reducers/publish.js | 1 + 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/react/containers/ChannelSelect/index.js b/react/containers/ChannelSelect/index.js index f90d0dc2..80084296 100644 --- a/react/containers/ChannelSelect/index.js +++ b/react/containers/ChannelSelect/index.js @@ -7,6 +7,7 @@ const mapStateToProps = ({ channel, publish }) => { loggedInChannelName: channel.loggedInChannel.name, publishInChannel : publish.publishInChannel, selectedChannel : publish.selectedChannel, + channelError : publish.error.channel, }; }; diff --git a/react/containers/ChannelSelect/view.jsx b/react/containers/ChannelSelect/view.jsx index 3042895d..9f4abf40 100644 --- a/react/containers/ChannelSelect/view.jsx +++ b/react/containers/ChannelSelect/view.jsx @@ -24,6 +24,7 @@ class ChannelSelect extends React.Component { render () { return (
+

{this.props.channelError}

@@ -36,7 +37,6 @@ class ChannelSelect extends React.Component { { this.props.publishInChannel && (
-

{this.props.channelError}

diff --git a/react/containers/PublishForm/index.js b/react/containers/PublishForm/index.js index e83ae9e1..df1614b6 100644 --- a/react/containers/PublishForm/index.js +++ b/react/containers/PublishForm/index.js @@ -14,6 +14,7 @@ const mapStateToProps = ({ channel, publish }) => { license : publish.metadata.license, nsfw : publish.metadata.nsfw, publishInChannel : publish.publishInChannel, + selectedChannel : publish.selectedChannel, fileError : publish.error.file, urlError : publish.error.url, publishSubmitError: publish.error.publishSubmit, @@ -34,6 +35,9 @@ const mapDispatchToProps = dispatch => { onPublishStatusChange: (status, message) => { dispatch(updatePublishStatus(status, message)); }, + onChannelSelectionError: (value) => { + dispatch(updateError('channel', value)); + }, onPublishSubmitError: (value) => { dispatch(updateError('publishSubmit', value)); }, diff --git a/react/containers/PublishForm/view.jsx b/react/containers/PublishForm/view.jsx index 56bf769b..5e596240 100644 --- a/react/containers/PublishForm/view.jsx +++ b/react/containers/PublishForm/view.jsx @@ -10,11 +10,24 @@ import * as publishStates from 'constants/publish_claim_states'; class PublishForm extends React.Component { constructor (props) { super(props); - this.validatePublishRequest = this.validatePublishRequest.bind(this); + this.validateChannelSelection = this.validateChannelSelection.bind(this); + this.validatePublishParams = this.validatePublishParams.bind(this); this.makePublishRequest = this.makePublishRequest.bind(this); this.publish = this.publish.bind(this); } - validatePublishRequest () { + validateChannelSelection () { + // make sure all required data is provided + return new Promise((resolve, reject) => { + // if publishInChannel is true, is a channel selected & logged in? + if (this.props.publishInChannel && (this.props.selectedChannel !== this.props.loggedInChannel.name)) { + // update state with error + this.props.onChannelSelectionError('Select "Anonymous" or log in to a channel'); + // reject this promise + return reject(new Error('Fix the channel')); + } + }); + } + validatePublishParams () { // make sure all required data is provided return new Promise((resolve, reject) => { // is there a file? @@ -28,10 +41,6 @@ class PublishForm extends React.Component { if (this.props.urlError) { return reject(new Error('Fix the url')); } - // if publishInChannel is true, is a channel logged in (or selected) - if (this.props.publishInChannel && !this.props.loggedInChannel.name) { - return reject(new Error('Select "Anonymous" or log in to a channel')); - } // is the claim available? resolve(); }); @@ -85,7 +94,7 @@ class PublishForm extends React.Component { thumbnail : this.props.thumbnail, }; if (this.props.publishInChannel) { - metadata['channelName'] = this.props.loggedInChannel.name; + metadata['channelName'] = this.props.selectedChannel; } return metadata; } @@ -103,7 +112,10 @@ class PublishForm extends React.Component { publish () { // publish the asset const that = this; - this.validatePublishRequest() + this.validateChannelSelection() + .then(() => { + return that.validatePublishRequest(); + }) .then(() => { const metadata = that.createMetadata(); // publish the claim diff --git a/react/reducers/publish.js b/react/reducers/publish.js index 108d84bf..1195a37d 100644 --- a/react/reducers/publish.js +++ b/react/reducers/publish.js @@ -12,6 +12,7 @@ const initialState = { error: { file : null, url : null, + channel : null, publishSubmit: null, }, file : null,