diff --git a/public/assets/js/createChannelFunctions.js b/public/assets/js/createChannelFunctions.js
index 1e3f4957..982e730d 100644
--- a/public/assets/js/createChannelFunctions.js
+++ b/public/assets/js/createChannelFunctions.js
@@ -33,7 +33,7 @@ function publishNewChannel (event) {
return sendAuthRequest(userName, password, '/signup') // post the request
})
.then(result => {
- setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId);
+ setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
showChannelCreateDoneDisplay();
window.location = '/';
})
diff --git a/public/assets/js/generalFunctions.js b/public/assets/js/generalFunctions.js
index 6ba5515b..0343b7fb 100644
--- a/public/assets/js/generalFunctions.js
+++ b/public/assets/js/generalFunctions.js
@@ -131,7 +131,7 @@ function clearCookie(name) {
document.cookie = `${name}=; expires=Thu, 01-Jan-1970 00:00:01 GMT;`;
}
-function setUserCookies(channelName, channelClaimId, shortChannelId) {
+function setUserCookies(channelName, shortChannelId, channelClaimId) {
setCookie('channel_name', channelName)
setCookie('channel_claim_id', channelClaimId);
setCookie('short_channel_id', shortChannelId);
diff --git a/public/assets/js/loginFunctions.js b/public/assets/js/loginFunctions.js
index cc3580f4..54a8312a 100644
--- a/public/assets/js/loginFunctions.js
+++ b/public/assets/js/loginFunctions.js
@@ -8,7 +8,7 @@ function loginToChannel (event) {
return sendAuthRequest(userName, password, '/login')
})
.then(result => {
- setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId);
+ setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
// if user is on the home page, update the needed elements without reloading
window.location = '/';
})
diff --git a/react/components/AnonymousOrChannelSelect.jsx b/react/components/AnonymousOrChannelSelect.jsx
index b956887a..da93a88d 100644
--- a/react/components/AnonymousOrChannelSelect.jsx
+++ b/react/components/AnonymousOrChannelSelect.jsx
@@ -17,20 +17,16 @@ class AnonymousOrChannelSelect extends React.Component {
}
render () {
return (
-
-
+
+
+
+
+
);
}
}
diff --git a/react/components/ChannelCreateForm.jsx b/react/components/ChannelCreateForm.jsx
index c4cef7a4..f289ec5a 100644
--- a/react/components/ChannelCreateForm.jsx
+++ b/react/components/ChannelCreateForm.jsx
@@ -1,5 +1,9 @@
import React from 'react';
+import {connect} from 'react-redux';
+import {updateLoggedInChannel} from '../actions';
import { makeGetRequest, makePostRequest } from '../utils/xhr.js';
+import { setUserCookies } from '../utils/cookies.js';
+import { replaceChannelSelectionInNavBar } from '../utils/pageUpdate.js';
class ChannelCreateForm extends React.Component {
constructor (props) {
@@ -10,25 +14,24 @@ class ChannelCreateForm extends React.Component {
password: null,
status : null,
};
+ this.cleanseChannelInput = this.cleanseChannelInput.bind(this);
this.handleChannelInput = this.handleChannelInput.bind(this);
this.handleInput = this.handleInput.bind(this);
- this.cleanseInput = this.cleanseInput.bind(this);
this.checkChannelIsAvailable = this.checkChannelIsAvailable.bind(this);
this.createChannel = this.createChannel.bind(this);
}
- handleChannelInput (event) {
- event.preventDefault();
- const name = event.target.name;
- let value = event.target.value;
- value = this.cleanseInput(value);
- this.setState({[name]: value});
- this.checkChannelIsAvailable(value);
- }
- cleanseInput (input) {
+ cleanseChannelInput (input) {
input = input.replace(/\s+/g, '-'); // replace spaces with dashes
input = input.replace(/[^A-Za-z0-9-]/g, ''); // remove all characters that are not A-Z, a-z, 0-9, or '-'
return input;
}
+ handleChannelInput (event) {
+ event.preventDefault();
+ let value = event.target.value;
+ value = this.cleanseChannelInput(value);
+ this.setState({channel: value});
+ this.checkChannelIsAvailable(value);
+ }
handleInput (event) {
event.preventDefault();
const name = event.target.name;
@@ -65,10 +68,9 @@ class ChannelCreateForm extends React.Component {
this.setState({status: 'We are publishing your new channel. Sit tight...'});
makePostRequest(url, params)
.then(result => {
- that.props.updateLoggedInChannelOutsideReact(result.channelName, result.channelClaimId, result.shortChannelId);
- that.props.updateUploaderState('loggedInChannelName', result.channelName);
- that.props.updateUploaderState('loggedInChannelShortId', result.shortChannelId);
- that.props.selectOption(result.channelName);
+ that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
+ setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
+ replaceChannelSelectionInNavBar(result.channelName);
})
.catch(error => {
console.log('create channel failure:', error);
@@ -91,7 +93,7 @@ class ChannelCreateForm extends React.Component {
@@ -101,13 +103,13 @@ class ChannelCreateForm extends React.Component {
-
+
) : (
@@ -118,4 +120,12 @@ class ChannelCreateForm extends React.Component {
}
}
-module.exports = ChannelCreateForm;
+const mapDispatchToProps = dispatch => {
+ return {
+ onChannelLogin: (name, shortId, longId) => {
+ dispatch(updateLoggedInChannel(name, shortId, longId));
+ },
+ };
+};
+
+export default connect(null, mapDispatchToProps)(ChannelCreateForm);
diff --git a/react/components/ChannelLoginForm.jsx b/react/components/ChannelLoginForm.jsx
index 0c06fc58..b23ea0f8 100644
--- a/react/components/ChannelLoginForm.jsx
+++ b/react/components/ChannelLoginForm.jsx
@@ -1,5 +1,9 @@
import React from 'react';
import { makePostRequest } from '../utils/xhr.js';
+import { connect } from 'react-redux';
+import { updateLoggedInChannel } from '../actions';
+import { setUserCookies } from '../utils/cookies.js';
+import { replaceChannelSelectionInNavBar } from '../utils/pageUpdate.js';
class ChannelLoginForm extends React.Component {
constructor (props) {
@@ -25,17 +29,16 @@ class ChannelLoginForm extends React.Component {
const that = this;
makePostRequest(url, params)
.then(result => {
- that.props.updateLoggedInChannelOutsideReact(result.channelName, result.channelClaimId, result.shortChannelId);
- that.props.updateUploaderState('loggedInChannelName', result.channelName);
- that.props.updateUploaderState('loggedInChannelShortId', result.shortChannelId);
- that.props.selectOption(result.channelName);
+ that.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
+ setUserCookies(result.channelName, result.shortChannelId, result.channelClaimId);
+ replaceChannelSelectionInNavBar(result.channelName);
})
.catch(error => {
console.log('login error', error);
if (error.message) {
that.setState({'error': error.message});
} else {
- that.setState({'error': 'There was an error logging into your channel'});
+ that.setState({'error': error});
}
});
}
@@ -71,4 +74,12 @@ class ChannelLoginForm extends React.Component {
}
}
-module.exports = ChannelLoginForm;
+const mapDispatchToProps = dispatch => {
+ return {
+ onChannelLogin: (name, shortId, longId) => {
+ dispatch(updateLoggedInChannel(name, shortId, longId));
+ },
+ };
+};
+
+export default connect(null, mapDispatchToProps)(ChannelLoginForm);
diff --git a/react/components/ChannelSelector.jsx b/react/components/ChannelSelector.jsx
index f93bf0ba..08e78274 100644
--- a/react/components/ChannelSelector.jsx
+++ b/react/components/ChannelSelector.jsx
@@ -2,7 +2,6 @@ import React from 'react';
import ChannelLoginForm from './ChannelLoginForm.jsx';
import ChannelCreateForm from './ChannelCreateForm.jsx';
import { connect } from 'react-redux';
-import { setUserCookies } from '../utils/cookies.js';
const LOGIN = 'login';
const CREATE = 'create';
@@ -15,12 +14,17 @@ class ChannelSelector extends React.Component {
};
this.handleSelection = this.handleSelection.bind(this);
this.selectOption = this.selectOption.bind(this);
- this.replaceChannelSelectionInNavBar = this.replaceChannelSelectionInNavBar.bind(this);
- this.updateLoggedInChannelOutsideReact = this.updateLoggedInChannelOutsideReact.bind(this);
}
componentWillMount () {
+ console.log('ChannelSelector will mount.');
if (this.props.loggedInChannelName) {
- this.setState({ optionState: this.props.loggedInChannelName });
+ this.selectOption(this.props.loggedInChannelName);
+ }
+ }
+ componentWillReceiveProps ({ loggedInChannelName }) {
+ console.log('ChannelSelector will receive props');
+ if (loggedInChannelName) {
+ this.selectOption(loggedInChannelName);
}
}
handleSelection (event) {
@@ -30,39 +34,12 @@ class ChannelSelector extends React.Component {
selectOption (option) {
this.setState({optionState: option});
}
- updateLoggedInChannelOutsideReact (channelName, channelClaimId, shortChannelId) {
- // update anywhere on page that needs to be updated outside of this component
- setUserCookies(channelName, channelClaimId, shortChannelId);
- this.replaceChannelSelectionInNavBar(channelName);
- }
- replaceChannelSelectionInNavBar (loggedInChannel) {
- // remove the old channel option
- const oldChannel = document.getElementById('nav-bar-channel-select-channel-option');
- if (oldChannel) {
- oldChannel.parentNode.removeChild(oldChannel);
- }
- // create new channel option & select it
- const newChannelOption = document.createElement('option');
- newChannelOption.setAttribute('value', loggedInChannel);
- newChannelOption.setAttribute('id', 'nav-bar-channel-select-channel-option');
- newChannelOption.setAttribute('selected', '');
- newChannelOption.innerText = loggedInChannel;
- // add the new option
- const channelSelect = document.getElementById('nav-bar-channel-select');
- channelSelect.style.display = 'inline-block';
- channelSelect.insertBefore(newChannelOption, channelSelect.firstChild);
- // hide login
- const navBarLoginLink = document.getElementById('nav-bar-login-link');
- navBarLoginLink.style.display = 'none';
- }
render () {
return (
{ this.props.publishInChannel && (
-
-
+
{this.props.channelError}
-
@@ -73,18 +50,9 @@ class ChannelSelector extends React.Component {
- { (this.state.optionState === LOGIN) &&
-
}
- { (this.state.optionState === CREATE) &&
-
}
+ { (this.state.optionState === LOGIN) &&
}
+
+ { (this.state.optionState === CREATE) &&
}
)}
diff --git a/react/components/PublishForm.jsx b/react/components/PublishForm.jsx
index 27a97fcf..da502a22 100644
--- a/react/components/PublishForm.jsx
+++ b/react/components/PublishForm.jsx
@@ -22,12 +22,12 @@ class PublishForm extends React.Component {
this.publish = this.publish.bind(this);
}
componentWillMount () {
- // check for whether a channel is logged in
- // if so, set the loggedInChannel to the channel name
+ // check for whether a channel is already logged in
const loggedInChannelName = getCookie('channel_name');
const loggedInChannelShortId = getCookie('short_channel_id');
const loggedInChannelLongId = getCookie('long_channel_id');
- this.props.onChannelUpdate(loggedInChannelName, loggedInChannelShortId, loggedInChannelLongId);
+ console.log(`channel cookies found: ${loggedInChannelName} ${loggedInChannelShortId} ${loggedInChannelLongId}`);
+ this.props.onChannelLogin(loggedInChannelName, loggedInChannelShortId, loggedInChannelLongId);
}
publish () {
// publish the asset
@@ -51,9 +51,17 @@ class PublishForm extends React.Component {
-
-
-
+
+
+
+
+
+
+
{
onFileClear: () => {
dispatch(clearFile());
},
- onChannelUpdate: (name, shortId, longId) => {
+ onChannelLogin: (name, shortId, longId) => {
dispatch(updateLoggedInChannel(name, shortId, longId));
},
};
diff --git a/react/components/PublishUrlInput.jsx b/react/components/PublishUrlInput.jsx
index 2ddacc13..3147287e 100644
--- a/react/components/PublishUrlInput.jsx
+++ b/react/components/PublishUrlInput.jsx
@@ -56,23 +56,17 @@ class UrlChooser extends React.Component {
render () {
return (
-
+
{this.state.error}
+
+
+
-
{this.state.error}
+
{this.state.host} /
-
-
-
-
- {this.state.host} /
-
-
-
-
- { (this.props.claim && !this.state.error) && {'\u2713'} }
-
-
+
+
+ { (this.props.claim && !this.state.error) && {'\u2713'} }
);
diff --git a/react/reducers/index.js b/react/reducers/index.js
index 6a1871d9..53e08abf 100644
--- a/react/reducers/index.js
+++ b/react/reducers/index.js
@@ -9,13 +9,12 @@ const initialState = {
shortId: null,
longId : null,
},
- loggedInChannelShortId: null,
- publishInChannel : false,
- publishStatus : null,
- error : null,
- file : null,
- claim : '',
- metadata : {
+ publishInChannel: false,
+ publishStatus : null,
+ error : null,
+ file : null,
+ claim : '',
+ metadata : {
title : '',
thumbnail : '',
description: '',
diff --git a/react/utils/cookies.js b/react/utils/cookies.js
index 37811c20..0214cdd9 100644
--- a/react/utils/cookies.js
+++ b/react/utils/cookies.js
@@ -17,7 +17,7 @@ module.exports = {
setCookie (key, value) {
document.cookie = `${key}=${value}`;
},
- setUserCookies (channelName, channelClaimId, shortChannelId) {
+ setUserCookies (channelName, shortChannelId, channelClaimId) {
module.exports.setCookie('channel_name', channelName)
module.exports.setCookie('channel_claim_id', channelClaimId);
module.exports.setCookie('short_channel_id', shortChannelId);
diff --git a/react/utils/pageUpdate.js b/react/utils/pageUpdate.js
new file mode 100644
index 00000000..94b33767
--- /dev/null
+++ b/react/utils/pageUpdate.js
@@ -0,0 +1,22 @@
+module.exports = {
+ replaceChannelSelectionInNavBar (loggedInChannel) {
+ // remove the old channel option
+ const oldChannel = document.getElementById('nav-bar-channel-select-channel-option');
+ if (oldChannel) {
+ oldChannel.parentNode.removeChild(oldChannel);
+ }
+ // create new channel option & select it
+ const newChannelOption = document.createElement('option');
+ newChannelOption.setAttribute('value', loggedInChannel);
+ newChannelOption.setAttribute('id', 'nav-bar-channel-select-channel-option');
+ newChannelOption.setAttribute('selected', '');
+ newChannelOption.innerText = loggedInChannel;
+ // add the new option
+ const channelSelect = document.getElementById('nav-bar-channel-select');
+ channelSelect.style.display = 'inline-block';
+ channelSelect.insertBefore(newChannelOption, channelSelect.firstChild);
+ // hide login
+ const navBarLoginLink = document.getElementById('nav-bar-login-link');
+ navBarLoginLink.style.display = 'none';
+ },
+}