From 0052717297b5f17fcc9097d7f887a89632c23d78 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Fri, 5 Jan 2018 11:09:32 -0800 Subject: [PATCH] pass logged in channel name to channel selector --- react/components/channelSelector.jsx | 11 ++++++---- react/components/publishForm.jsx | 2 +- react/uploader.js | 30 +++++++++++++++++++++------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/react/components/channelSelector.jsx b/react/components/channelSelector.jsx index e3f73c6e..84fa1e9e 100644 --- a/react/components/channelSelector.jsx +++ b/react/components/channelSelector.jsx @@ -33,7 +33,7 @@ class ChannelSelector extends React.Component { constructor (props) { super(props); this.state = { - displayCreateOrLogin: LOGIN, + displayCreateOrLogin: null, }; this.toggleCreateOrLogin = this.toggleCreateOrLogin.bind(this); } @@ -41,8 +41,10 @@ class ChannelSelector extends React.Component { const selectedOption = event.target.selectedOptions[0].value; if (selectedOption === 'login') { this.setState({ displayCreateOrLogin: LOGIN }); - } else { + } else if (selectedOption === 'create') { this.setState({ displayCreateOrLogin: CREATE }); + } else { + this.setState({ displayCreateOrLogin: null }); } } render () { @@ -57,13 +59,14 @@ class ChannelSelector extends React.Component {
- { (this.state.displayCreateOrLogin === LOGIN) ? : } + { (this.state.displayCreateOrLogin === LOGIN) && } + { (this.state.displayCreateOrLogin === CREATE) && } )} diff --git a/react/components/publishForm.jsx b/react/components/publishForm.jsx index 567a174c..78c9289d 100644 --- a/react/components/publishForm.jsx +++ b/react/components/publishForm.jsx @@ -97,7 +97,7 @@ class PublishForm extends React.Component { { - if (xhttp.readyState == 4 ) { - if ( xhttp.status == 200) { + if (xhttp.readyState === 4) { + if (xhttp.status === 200) { resolve(xhttp.response); - } else if (xhttp.status == 403) { + } else if (xhttp.status === 403) { reject('Wrong channel name or password'); } else { reject('request failed with status:' + xhttp.status); @@ -92,6 +93,21 @@ class Uploader extends React.Component { name = name.replace(/[^A-Za-z0-9-]/g, ''); // remove all characters that are not A-Z, a-z, 0-9, or '-' return name; } + getCookie (cname) { + const name = cname + '='; + const decodedCookie = decodeURIComponent(document.cookie); + const ca = decodedCookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) === ' ') { + c = c.substring(1); + } + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length); + } + } + return ''; + } render () { return (