diff --git a/react/components/channelCreateForm.jsx b/react/components/channelCreateForm.jsx new file mode 100644 index 00000000..ad6192f7 --- /dev/null +++ b/react/components/channelCreateForm.jsx @@ -0,0 +1,97 @@ +import React from 'react'; + +function ChannelSuccess (message) { + return ( +
+

{this.props.message}

+
+ ); +} + +function ChannelInProgress () { + return ( +
+

Creating your new channel. This may take a few seconds...

+
+
+ ); +} + + + +class ChannelCreateForm extends React.Component { + constructor (props) { + super(props); + this.state = { + error : null, + channel : null, + password: null, + status : null, + }; + this.handleChannelInput = this.handleChannelInput.bind(this); + this.handleInput = this.handleInput.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.props.cleanseInput(value); + this.setState({[name]: value}); + this.checkChannelIsAvailable(value); + } + handleInput (event) { + event.preventDefault(); + const name = event.target.name; + const value = event.target.value; + this.setState({[name]: value}); + } + checkChannelIsAvailable (channel) { + const that = this; + this.props.makeGetRequest(`/api/channel-is-available/${channel}`) + .then(() => { + that.setState({urlError: null}); + }) + .catch((error) => { + that.setState({error: error.message}); + }); + } + createChannel (event) { + event.preventDefault(); + // publishNewChannel(event) + } + render () { + return ( +
+

{this.state.error}

+
+
+ +
+
+ @ + + {'\u2713'} +
+
+
+
+
+ +
+
+ +
+
+
+ +
+ +
+
+ ); + } +} + +module.exports = ChannelCreateForm; diff --git a/react/components/channelLoginForm.jsx b/react/components/channelLoginForm.jsx new file mode 100644 index 00000000..b9f3eba0 --- /dev/null +++ b/react/components/channelLoginForm.jsx @@ -0,0 +1,55 @@ +import React from 'react'; + +class ChannelLoginForm extends React.Component { + constructor (props) { + super(props); + this.state = { + error : null, + name : null, + password: null, + }; + this.handleInput = this.handleInput.bind(this); + this.loginToChannel = this.loginToChannel.bind(this); + } + handleInput (event) { + event.preventDefault(); + const name = event.target.name; + const value = event.target.value; + this.setState({[name]: value}); + } + loginToChannel (event) { + event.preventDefault(); + } + render () { + return ( +
+

{this.state.error}

+
+
+ +
+
+ @ + +
+
+
+
+
+ +
+
+ +
+
+
+ +
+ +
+
+ ); + } +} + +module.exports = ChannelLoginForm; diff --git a/react/components/channelSelector.jsx b/react/components/channelSelector.jsx index 84fa1e9e..c3168984 100644 --- a/react/components/channelSelector.jsx +++ b/react/components/channelSelector.jsx @@ -1,42 +1,23 @@ import React from 'react'; +import ChannelLoginForm from './channelLoginForm.jsx'; +import ChannelCreateForm from './channelCreateForm.jsx'; const LOGIN = 'login'; const CREATE = 'create'; -class ChannelLoginForm extends React.Component { - constructor (props) { - super(props); - } - render () { - return ( -
-

Channel Login Form

-
- ); - } -} - -class ChannelCreateForm extends React.Component { - constructor (props) { - super(props); - } - render () { - return ( -
-

Create Channel Form

-
- ); - } -} - class ChannelSelector extends React.Component { constructor (props) { super(props); this.state = { - displayCreateOrLogin: null, + displayCreateOrLogin: LOGIN, }; this.toggleCreateOrLogin = this.toggleCreateOrLogin.bind(this); } + componentWillMount () { + if (this.props.loggedInChannelName) { + this.setState({ displayCreateOrLogin: null }); + } + } toggleCreateOrLogin (event) { const selectedOption = event.target.selectedOptions[0].value; if (selectedOption === 'login') { @@ -66,7 +47,11 @@ class ChannelSelector extends React.Component { { (this.state.displayCreateOrLogin === LOGIN) && } - { (this.state.displayCreateOrLogin === CREATE) && } + { (this.state.displayCreateOrLogin === CREATE) && + } )} diff --git a/react/components/dropzone.jsx b/react/components/dropzone.jsx index 63a015f4..4336b283 100644 --- a/react/components/dropzone.jsx +++ b/react/components/dropzone.jsx @@ -126,7 +126,7 @@ class Dropzone extends React.Component { setClaimNameFromFileName (fileName) { console.log('setClaimNameFromFileName', fileName); const fileNameWithoutEnding = fileName.substring(0, fileName.lastIndexOf('.')); - const cleanClaimName = this.props.cleanseClaimName(fileNameWithoutEnding); + const cleanClaimName = this.props.cleanseInput(fileNameWithoutEnding); this.props.updateUploaderState('claim', cleanClaimName); } render () { diff --git a/react/components/publishForm.jsx b/react/components/publishForm.jsx index 78c9289d..61f3a734 100644 --- a/react/components/publishForm.jsx +++ b/react/components/publishForm.jsx @@ -42,9 +42,6 @@ class AnonymousOrChannelSelect extends React.Component { class PublishForm extends React.Component { constructor (props) { super(props); - this.state = { - channelError: null, - } // set defaults this.updateUploaderState = this.updateUploaderState.bind(this); this.clearUploaderState = this.clearUploaderState.bind(this); @@ -73,7 +70,7 @@ class PublishForm extends React.Component { - + { (this.props.file.type === 'video/mp4') && }
@@ -85,26 +82,23 @@ class PublishForm extends React.Component { publishToChannel={this.props.publishToChannel} loggedInChannelName={this.props.loggedInChannelName} loggedInChannelShortId={this.props.loggedInChannelShortId} - cleanseClaimName={this.props.cleanseClaimName} + cleanseInput={this.props.cleanseInput} updateUploaderState={this.updateUploaderState} makeGetRequest={this.props.makeGetRequest} /> - - - { (this.props.file.type === 'video/mp4') && } -
diff --git a/react/components/urlChooser.jsx b/react/components/urlChooser.jsx index bac01873..fa02fc9a 100644 --- a/react/components/urlChooser.jsx +++ b/react/components/urlChooser.jsx @@ -17,9 +17,9 @@ class UrlChooser extends React.Component { constructor (props) { super(props); this.state = { - urlError : null, - urlBeginning: 'spee.ch', - urlMiddle : null, + error : null, + host : 'spee.ch', + urlMiddle: null, }; this.handleInput = this.handleInput.bind(this); this.checkClaimIsAvailable = this.checkClaimIsAvailable.bind(this); @@ -28,7 +28,7 @@ class UrlChooser extends React.Component { event.preventDefault(); let value = event.target.value; const name = event.target.name; - value = this.props.cleanseClaimName(value); + value = this.props.cleanseInput(value); this.props.updateUploaderState(name, value); this.checkClaimIsAvailable(value); } @@ -36,10 +36,10 @@ class UrlChooser extends React.Component { const that = this; this.props.makeGetRequest(`/api/claim-is-available/${claim}`) .then(() => { - that.setState({urlError: null}); + that.setState({'error': null}); }) .catch((error) => { - that.setState({urlError: error.message}); + that.setState({'error': error.message}); }); } render () { @@ -47,18 +47,18 @@ class UrlChooser extends React.Component {
-

{this.state.urlError}

+

{this.state.error}

- {this.state.urlBeginning} / + {this.state.host} / - { (this.props.claim && !this.state.urlError) && ( + { (this.props.claim && !this.state.error) && ( {'\u2713'} )} diff --git a/react/uploader.js b/react/uploader.js index 8791aeb2..37b28a5c 100644 --- a/react/uploader.js +++ b/react/uploader.js @@ -31,7 +31,7 @@ class Uploader extends React.Component { this.clearUploaderState = this.clearUploaderState.bind(this); this.makeGetRequest = this.makeGetRequest.bind(this); this.makePostRequest = this.makePostRequest.bind(this); - this.cleanseClaimName = this.cleanseClaimName.bind(this); + this.cleanseInput = this.cleanseInput.bind(this); this.getCookie = this.getCookie.bind(this); } componentDidMount () { @@ -88,10 +88,10 @@ class Uploader extends React.Component { xhttp.send(params); }); } - cleanseClaimName (name) { - name = name.replace(/\s+/g, '-'); // replace spaces with dashes - name = name.replace(/[^A-Za-z0-9-]/g, ''); // remove all characters that are not A-Z, a-z, 0-9, or '-' - return name; + cleanseInput (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; } getCookie (cname) { const name = cname + '='; @@ -114,7 +114,7 @@ class Uploader extends React.Component { { this.state.showComponent === DROPZONE && } { this.state.showComponent === DETAILS && @@ -122,7 +122,7 @@ class Uploader extends React.Component { updateUploaderState={this.updateUploaderState} clearUploaderState={this.clearUploaderState} makeGetRequest={this.makeGetRequest} - cleanseClaimName={this.cleanseClaimName} + cleanseInput={this.cleanseInput} loggedInChannelName={this.state.loggedInChannelName} loggedInChannelShortId={this.state.loggedInChannelShortId} publishToChannel={this.state.publishToChannel}