added display of publishing status
This commit is contained in:
parent
11a954a442
commit
4f6657a3b9
6 changed files with 89 additions and 48 deletions
|
@ -1,14 +1,6 @@
|
||||||
var stagedFiles = null;
|
var stagedFiles = null;
|
||||||
|
|
||||||
const publishFileFunctions = {
|
const publishFileFunctions = {
|
||||||
returnNullOrChannel: function () {
|
|
||||||
const channelRadio = document.getElementById('channel-radio');
|
|
||||||
if (channelRadio.checked) {
|
|
||||||
const channelInput = document.getElementById('channel-name-select');
|
|
||||||
return channelInput.value.trim();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
// Validate the publish submission and then trigger upload
|
// Validate the publish submission and then trigger upload
|
||||||
showUploadStartedMessage: function (){
|
showUploadStartedMessage: function (){
|
||||||
console.log('starting upload');
|
console.log('starting upload');
|
||||||
|
|
|
@ -52,9 +52,10 @@ export function setPublishInChannel (channel) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updatePublishStatus (status) {
|
export function updatePublishStatus (status, message) {
|
||||||
return {
|
return {
|
||||||
type: PUBLISH_STATUS_UPDATE,
|
type: PUBLISH_STATUS_UPDATE,
|
||||||
status,
|
status,
|
||||||
|
message,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,18 +1,49 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
class PublishStatus extends React.Component {
|
const LOAD_START = 'LOAD_START';
|
||||||
render () {
|
const LOADING = 'LOADING';
|
||||||
|
const PUBLISHING = 'PUBLISHING';
|
||||||
|
const SUCCESS = 'SUCCESS';
|
||||||
|
const FAILED = 'FAILED';
|
||||||
|
|
||||||
|
function PublishStatus ({ status, message }) {
|
||||||
return (
|
return (
|
||||||
<div id="publish-status" class="hidden">
|
<div className="row row--tall flex-container--column flex-container--center-center">
|
||||||
<div class="row row--margined">
|
{(status === LOAD_START) &&
|
||||||
<div id="publish-update" class="row align-content-center"></div>
|
<div className="row align-content-center">
|
||||||
<div id="publish-progress-bar" class="row align-content-center"></div>
|
<p>File is loading to server</p>
|
||||||
<div id="upload-percent" class="row align-content-center"></div>
|
<p className="blue">{message}</p>
|
||||||
<div>{this.props.status}</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
{(status === LOADING) &&
|
||||||
|
<div>
|
||||||
|
<div className="row align-content-center">
|
||||||
|
<p>File is loading to server</p>
|
||||||
|
<p className="blue">{message}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{(status === PUBLISHING) &&
|
||||||
|
<div className="row align-content-center">
|
||||||
|
<p>Upload complete. Your file is now being published on the blockchain...</p>
|
||||||
|
<p>PROGRESS BAR HERE</p>
|
||||||
|
<p>Curious what magic is happening here? <a className="link--primary" target="blank" href="https://lbry.io/faq/what-is-lbry">Learn more.</a></p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{(status === SUCCESS) &&
|
||||||
|
<div className="row align-content-center">
|
||||||
|
{message}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{(status === FAILED) &&
|
||||||
|
<div className="row align-content-center">
|
||||||
|
<p>Something went wrong...</p>
|
||||||
|
<p><strong>{message}</strong></p>
|
||||||
|
<p>For help, post the above error text in the #speech channel on the <a className="link--primary" href="https://discord.gg/YjYbwhS" target="_blank">lbry discord</a></p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = PublishStatus;
|
export default PublishStatus;
|
||||||
|
|
|
@ -10,6 +10,12 @@ import { connect } from 'react-redux';
|
||||||
import { getCookie } from '../utils/cookies.js';
|
import { getCookie } from '../utils/cookies.js';
|
||||||
import { selectFile, clearFile, updateLoggedInChannel, updatePublishStatus } from '../actions';
|
import { selectFile, clearFile, updateLoggedInChannel, updatePublishStatus } from '../actions';
|
||||||
|
|
||||||
|
const LOAD_START = 'LOAD_START';
|
||||||
|
const LOADING = 'LOADING';
|
||||||
|
const PUBLISHING = 'PUBLISHING';
|
||||||
|
const SUCCESS = 'SUCCESS';
|
||||||
|
const FAILED = 'FAILED';
|
||||||
|
|
||||||
class PublishForm extends React.Component {
|
class PublishForm extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -54,18 +60,18 @@ class PublishForm extends React.Component {
|
||||||
const fd = this.appendDataToFormData(file, metadata);
|
const fd = this.appendDataToFormData(file, metadata);
|
||||||
const that = this;
|
const that = this;
|
||||||
xhr.upload.addEventListener('loadstart', function () {
|
xhr.upload.addEventListener('loadstart', function () {
|
||||||
that.props.onPublishStatusChange('upload started');
|
that.props.onPublishStatusChange(LOAD_START, 'upload started');
|
||||||
});
|
});
|
||||||
xhr.upload.addEventListener('progress', function (e) {
|
xhr.upload.addEventListener('progress', function (e) {
|
||||||
if (e.lengthComputable) {
|
if (e.lengthComputable) {
|
||||||
const percentage = Math.round((e.loaded * 100) / e.total);
|
const percentage = Math.round((e.loaded * 100) / e.total);
|
||||||
that.props.onPublishStatusChange(`upload progress: ${percentage}%`);
|
|
||||||
console.log('progress:', percentage);
|
console.log('progress:', percentage);
|
||||||
|
that.props.onPublishStatusChange(LOADING, `${percentage}%`);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
xhr.upload.addEventListener('load', function () {
|
xhr.upload.addEventListener('load', function () {
|
||||||
console.log('loaded 100%');
|
console.log('loaded 100%');
|
||||||
that.props.onPublishStatusChange(`Upload complete. Your file is now being published on the blockchain...`);
|
that.props.onPublishStatusChange(PUBLISHING, null);
|
||||||
}, false);
|
}, false);
|
||||||
xhr.open('POST', uri, true);
|
xhr.open('POST', uri, true);
|
||||||
xhr.onreadystatechange = function () {
|
xhr.onreadystatechange = function () {
|
||||||
|
@ -73,11 +79,11 @@ class PublishForm extends React.Component {
|
||||||
console.log('publish response:', xhr.response);
|
console.log('publish response:', xhr.response);
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
console.log('publish complete!');
|
console.log('publish complete!');
|
||||||
that.props.onPublishStatusChange(JSON.parse(xhr.response).message);
|
that.props.onPublishStatusChange(SUCCESS, JSON.parse(xhr.response).message);
|
||||||
} else if (xhr.status === 502) {
|
} else if (xhr.status === 502) {
|
||||||
that.props.onPublishStatusChange('Spee.ch was not able to get a response from the LBRY network.');
|
that.props.onPublishStatusChange(FAILED, 'Spee.ch was not able to get a response from the LBRY network.');
|
||||||
} else {
|
} else {
|
||||||
that.props.onPublishStatusChange(JSON.parse(xhr.response).message);
|
that.props.onPublishStatusChange(FAILED, JSON.parse(xhr.response).message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -211,8 +217,8 @@ const mapDispatchToProps = dispatch => {
|
||||||
onChannelLogin: (name, shortId, longId) => {
|
onChannelLogin: (name, shortId, longId) => {
|
||||||
dispatch(updateLoggedInChannel(name, shortId, longId));
|
dispatch(updateLoggedInChannel(name, shortId, longId));
|
||||||
},
|
},
|
||||||
onPublishStatusChange: (status) => {
|
onPublishStatusChange: (status, message) => {
|
||||||
dispatch(updatePublishStatus(status));
|
dispatch(updatePublishStatus(status, message));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,24 +5,29 @@ import PublishStatus from '../components/PublishStatus.jsx';
|
||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
|
|
||||||
class PublishTool extends React.Component {
|
class PublishTool extends React.Component {
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
render () {
|
render () {
|
||||||
|
if (this.props.file) {
|
||||||
|
if (this.props.status) {
|
||||||
return (
|
return (
|
||||||
<div className="row row--tall flex-container--column">
|
<PublishStatus
|
||||||
{ !this.props.file && <PreviewDropzone /> }
|
status={this.props.status}
|
||||||
{ this.props.file && <PublishForm /> }
|
message={this.props.message}
|
||||||
{ this.props.publishStatus && <PublishStatus /> }
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return <PublishForm />;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return <PreviewDropzone />;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = state => {
|
const mapStateToProps = state => {
|
||||||
return {
|
return {
|
||||||
file : state.file,
|
file : state.file,
|
||||||
publishStatus: state.publishStatus,
|
status : state.status.status,
|
||||||
|
message: state.status.message,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,14 @@ const initialState = {
|
||||||
longId : null,
|
longId : null,
|
||||||
},
|
},
|
||||||
publishInChannel: false,
|
publishInChannel: false,
|
||||||
publishStatus : null,
|
status : {
|
||||||
|
status : null,
|
||||||
|
message: null,
|
||||||
|
},
|
||||||
error : null,
|
error : null,
|
||||||
file : null,
|
file : null,
|
||||||
claim : '',
|
claim : '',
|
||||||
metadata : {
|
metadata: {
|
||||||
title : '',
|
title : '',
|
||||||
thumbnail : '',
|
thumbnail : '',
|
||||||
description: '',
|
description: '',
|
||||||
|
@ -59,8 +62,11 @@ export default function (state = initialState, action) {
|
||||||
});
|
});
|
||||||
case PUBLISH_STATUS_UPDATE:
|
case PUBLISH_STATUS_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
publishStatus: action.status,
|
status: Object.assign({}, state.metadata, {
|
||||||
})
|
status : action.status,
|
||||||
|
message: action.message,
|
||||||
|
}),
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue