React/Redux - publish component #323
|
@ -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);
|
||||||
|
|
|
@ -5,8 +5,9 @@ class Preview extends React.Component {
|
||||||
Generally you should avoid doing dom stuff/setting state in
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 : '',
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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',
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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
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,25 +15,32 @@ class Preview extends React.Component {
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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) {
|
||||||
|
console.log('Preview will receive props', newProps);
|
||||||
Generally you should avoid doing dom stuff/setting state in
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) {
|
||||||
Generally you should avoid doing dom stuff/setting state in
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);
|
this.previewFile(newProps.file);
|
||||||
}
|
}
|
||||||
|
if (newProps.thumbnail !== this.props.thumbnail) {
|
||||||
Generally you should avoid doing dom stuff/setting state in
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);
|
||||||
Generally you should avoid doing dom stuff/setting state in
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)});
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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
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;
|
||||||
if (file.type !== 'video/mp4') {
|
if (file.type !== 'video/mp4') {
|
||||||
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});
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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)});
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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}
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
Generally you should avoid doing dom stuff/setting state in
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
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
|
|
@ -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>
|
||||||
|
|
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