React/Redux - publish component #323

Merged
bones7242 merged 80 commits from react-upload into master 2018-01-25 22:43:20 +01:00
3 changed files with 61 additions and 39 deletions
Showing only changes of commit 0aa1456fc0 - Show all commits

View file

@ -4,10 +4,10 @@ function getRequest (url) {
xhttp.open('GET', url, true); xhttp.open('GET', url, true);
xhttp.responseType = 'json'; xhttp.responseType = 'json';
xhttp.onreadystatechange = () => { xhttp.onreadystatechange = () => {
if (xhttp.readyState == 4 ) { if (xhttp.readyState === 4 ) {
if ( xhttp.status == 200) { if ( xhttp.status === 200) {
resolve(xhttp.response); resolve(xhttp.response);
} else if (xhttp.status == 403) { } else if (xhttp.status === 403) {
reject('Wrong channel name or password'); reject('Wrong channel name or password');
} else { } else {
reject('request failed with status:' + xhttp.status); reject('request failed with status:' + xhttp.status);
@ -25,10 +25,10 @@ function postRequest (url, params) {
xhttp.responseType = 'json'; xhttp.responseType = 'json';
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.onreadystatechange = () => { xhttp.onreadystatechange = () => {
if (xhttp.readyState == 4 ) { if (xhttp.readyState === 4 ) {
if ( xhttp.status == 200) { if ( xhttp.status === 200) {
resolve(xhttp.response); resolve(xhttp.response);
} else if (xhttp.status == 401) { } else if (xhttp.status === 401) {
reject( new AuthenticationError('Wrong channel name or password')); reject( new AuthenticationError('Wrong channel name or password'));
} else { } else {
reject('request failed with status:' + xhttp.status); reject('request failed with status:' + xhttp.status);

View file

@ -5,8 +5,9 @@ class Preview extends React.Component {
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
constructor (props) { constructor (props) {
super(props); super(props);
this.state = { this.state = {
previewSource: '', imgSource : '',
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
} defaultThumbnail: '/assets/img/video_thumb_default.png',
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
};
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
this.previewFile = this.previewFile.bind(this); this.previewFile = this.previewFile.bind(this);
} }
componentWillMount () { componentWillMount () {
@ -14,7 +15,14 @@ class Preview extends React.Component {
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
this.previewFile(this.props.file); this.previewFile(this.props.file);
} }
componentWillReceiveProps (newProps) { componentWillReceiveProps (newProps) {
this.previewFile(newProps.file); console.log('Preview will receive props', newProps);
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
if (newProps.file !== this.props.file) {
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
this.previewFile(newProps.file);
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
}
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
if (newProps.thumbnail !== this.props.thumbnail) {
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
console.log('updating thumbnail', this.props.thumbnail);
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
this.setState({imgSource: (newProps.thumbnail || this.state.defaultThumbnail)});
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
}
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
} }
previewFile (file) { previewFile (file) {
const that = this; const that = this;
@ -22,17 +30,17 @@ class Preview extends React.Component {
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
const previewReader = new FileReader(); const previewReader = new FileReader();
previewReader.readAsDataURL(file); previewReader.readAsDataURL(file);
previewReader.onloadend = function () { previewReader.onloadend = function () {
that.setState({previewSource: previewReader.result}); that.setState({imgSource: previewReader.result});
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
}; };
} else { } else {
that.setState({previewSource: (this.props.thumbnail || '/assets/img/video_thumb_default.png')}); that.setState({imgSource: (this.props.thumbnail || this.state.defaultThumbnail)});
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
} }
} }
render () { render () {
return ( return (
<img <img
id="asset-preview" id="asset-preview"
src={this.state.previewSource} src={this.state.imgSource}
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
className={this.props.dimPreview ? 'dim' : ''} className={this.props.dimPreview ? 'dim' : ''}
alt="publish preview" alt="publish preview"
/> />

neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred
neb-b commented 2018-01-18 06:08:35 +01:00 (Migrated from github.com)
Review

Generally you should avoid doing dom stuff/setting state in componentWillMount. Especially since it seems that they will be removing it in a future React version.

componentDidMount is preferred

Generally you should avoid doing dom stuff/setting state in `componentWillMount`. Especially since it seems that they will be removing it in a future React version. `componentDidMount` is preferred

View file

@ -5,51 +5,56 @@ class PublishThumbnailInput extends React.Component {
super(props); super(props);
this.state = { this.state = {
videoPreviewSrc: null, videoPreviewSrc: null,
thumbnailError : null,
thumbnailInput : '',
} }
this.handleInput = this.handleInput.bind(this);
this.urlIsAnImage = this.urlIsAnImage.bind(this); this.urlIsAnImage = this.urlIsAnImage.bind(this);
this.testImage = this.testImage.bind(this); this.testImage = this.testImage.bind(this);
this.updateVideoThumb = this.updateVideoThumb.bind(this); this.updateVideoThumb = this.updateVideoThumb.bind(this);
} }
handleInput (event) {
event.preventDefault();
const value = event.target.value;
this.setState({thumbnailInput: value});
}
urlIsAnImage (url) { urlIsAnImage (url) {
return (url.match(/\.(jpeg|jpg|gif|png)$/) != null); return (url.match(/\.(jpeg|jpg|gif|png)$/) != null);
} }
testImage (url, timeoutT) { testImage (url) {
return new Promise(function (resolve, reject) { return new Promise((resolve, reject) => {
const timeout = timeoutT || 5000; const xhttp = new XMLHttpRequest();
let timer; xhttp.open('HEAD', url, true);
let img = new Image(); xhttp.onreadystatechange = () => {
img.onerror = img.onabort = function () { if (xhttp.readyState === 4) {
clearTimeout(timer); if (xhttp.status === 200) {
reject('error'); resolve();
} else {
reject();
}
}
}; };
img.onload = function () { xhttp.send();
clearTimeout(timer);
resolve('success');
};
timer = setTimeout(function () {
// reset .src to invalid URL so it stops previous
// loading, but doesn't trigger new load
img.src = '//!!!!/test.jpg';
reject('timeout');
}, timeout);
img.src = url;
}); });
} }
updateVideoThumb (event) { updateVideoThumb (event) {
var imageUrl = event.target.value; const imageUrl = event.target.value;
const that = this; const that = this;
if (this.urlIsAnImage(imageUrl)) { if (this.urlIsAnImage(imageUrl)) {
this.testImage(imageUrl, 3000) this.testImage(imageUrl, 3000)
.then(function (result) { .then(() => {
if (result === 'success') { console.log('thumbnail is a valid image');
that.props.onThumbnailChange('thumbnail', imageUrl); that.props.onThumbnailChange('thumbnail', imageUrl);
} else if (result === 'timeout') { that.setState({thumbnailError: null});
console.log('could not resolve the provided thumbnail image url');
}
}) })
.catch(error => { .catch(error => {
console.log('encountered an error loading thumbnail image url:', error); console.log('encountered an error loading thumbnail image url:', error);
that.props.onThumbnailChange('thumbnail', null);
that.setState({thumbnailError: 'That is an invalid image url'});
}); });
} else {
that.props.onThumbnailChange('thumbnail', null);
that.setState({thumbnailError: null});
} }
} }
render () { render () {
@ -59,7 +64,16 @@ class PublishThumbnailInput extends React.Component {
<label className="label">Thumbnail:</label> <label className="label">Thumbnail:</label>
</div><div className="column column--6 column--sml-10"> </div><div className="column column--6 column--sml-10">
<div className="input-text--primary"> <div className="input-text--primary">
<input type="text" id="claim-thumbnail-input" className="input-text input-text--full-width" placeholder="https://spee.ch/xyz/example.jpg" value={this.props.thumbnail} onInput={this.updateVideoThumb} /> <p className="info-message-placeholder info-message--failure">{this.state.thumbnailError}</p>
<input
type="text" id="claim-thumbnail-input"
className="input-text input-text--full-width"
placeholder="https://spee.ch/xyz/example.jpg"
value={this.state.thumbnailInput}
onChange={ (event) => {
this.handleInput(event);
this.updateVideoThumb(event);
}} />
</div> </div>
</div> </div>
</div> </div>