save optimize check to fix publish navigation file reloading

This commit is contained in:
jessop 2020-03-30 14:19:32 -04:00 committed by Sean Yesmunt
parent 8a1916423d
commit 50f7761bc2
3 changed files with 20 additions and 23 deletions

View file

@ -130,7 +130,7 @@
"imagesloaded": "^4.1.4", "imagesloaded": "^4.1.4",
"json-loader": "^0.5.4", "json-loader": "^0.5.4",
"lbry-format": "https://github.com/lbryio/lbry-format.git", "lbry-format": "https://github.com/lbryio/lbry-format.git",
"lbry-redux": "lbryio/lbry-redux#625a624b9c2d5839e25c1a592d69b9f312944fe0", "lbry-redux": "lbryio/lbry-redux#430f989809fed1ac310dbcacef926eb41bf6e6e5",
"lbryinc": "lbryio/lbryinc#19260fac560daaa4be2d4af372f28109ea96ebf9", "lbryinc": "lbryio/lbryinc#19260fac560daaa4be2d4af372f28109ea96ebf9",
"lint-staged": "^7.0.2", "lint-staged": "^7.0.2",
"localforage": "^1.7.1", "localforage": "^1.7.1",

View file

@ -18,6 +18,9 @@ const select = state => ({
balance: selectBalance(state), balance: selectBalance(state),
publishing: makeSelectPublishFormValue('publishing')(state), publishing: makeSelectPublishFormValue('publishing')(state),
ffmpegStatus: selectFfmpegStatus(state), ffmpegStatus: selectFfmpegStatus(state),
size: makeSelectPublishFormValue('fileSize')(state),
duration: makeSelectPublishFormValue('fileDur')(state),
isVid: makeSelectPublishFormValue('fileVid')(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
@ -26,7 +29,4 @@ const perform = dispatch => ({
showToast: message => dispatch(doToast({ message, isError: true })), showToast: message => dispatch(doToast({ message, isError: true })),
}); });
export default connect( export default connect(select, perform)(PublishPage);
select,
perform
)(PublishPage);

View file

@ -22,6 +22,9 @@ type Props = {
clearPublish: () => void, clearPublish: () => void,
ffmpegStatus: any, ffmpegStatus: any,
optimize: boolean, optimize: boolean,
size: number,
duration: number,
isVid: boolean,
}; };
function PublishFile(props: Props) { function PublishFile(props: Props) {
@ -37,13 +40,13 @@ function PublishFile(props: Props) {
clearPublish, clearPublish,
optimize, optimize,
ffmpegStatus = {}, ffmpegStatus = {},
size,
duration,
isVid,
} = props; } = props;
const { available } = ffmpegStatus; const { available } = ffmpegStatus;
const [duration, setDuration] = useState(0);
const [size, setSize] = useState(0);
const [oversized, setOversized] = useState(false); const [oversized, setOversized] = useState(false);
const [isVid, setIsVid] = useState(false);
const RECOMMENDED_BITRATE = 6000000; const RECOMMENDED_BITRATE = 6000000;
const TV_PUBLISH_SIZE_LIMIT: number = 1073741824; const TV_PUBLISH_SIZE_LIMIT: number = 1073741824;
const UPLOAD_SIZE_MESSAGE = 'Lbrytv uploads are limited to 1 GB. Download the app for unrestricted publishing.'; const UPLOAD_SIZE_MESSAGE = 'Lbrytv uploads are limited to 1 GB. Download the app for unrestricted publishing.';
@ -56,10 +59,8 @@ function PublishFile(props: Props) {
// clear warnings // clear warnings
useEffect(() => { useEffect(() => {
if (!filePath || filePath === '' || filePath.name === '') { if (!filePath || filePath === '') {
setDuration(0); updateOptimizeState(0, 0, false);
setSize(0);
setIsVid(false);
setOversized(false); setOversized(false);
} }
}, [filePath]); }, [filePath]);
@ -73,6 +74,10 @@ function PublishFile(props: Props) {
} }
} }
function updateOptimizeState(duration, size, isvid) {
updatePublishForm({ fileDur: duration, fileSize: size, fileVid: isvid });
}
function getBitrate(size, duration) { function getBitrate(size, duration) {
const s = Number(size); const s = Number(size);
const d = Number(duration); const d = Number(duration);
@ -177,8 +182,6 @@ function PublishFile(props: Props) {
// if electron, we'll set filePath to the path string because SDK is handling publishing. // if electron, we'll set filePath to the path string because SDK is handling publishing.
// if web, we set the filePath (dumb name) to the File() object // if web, we set the filePath (dumb name) to the File() object
// File.path will be undefined from web due to browser security, so it will default to the File Object. // File.path will be undefined from web due to browser security, so it will default to the File Object.
setSize(file ? file.size : 0);
setDuration(0);
setOversized(false); setOversized(false);
// select file, start to select a new one, then cancel // select file, start to select a new one, then cancel
@ -195,21 +198,15 @@ function PublishFile(props: Props) {
const video = document.createElement('video'); const video = document.createElement('video');
video.preload = 'metadata'; video.preload = 'metadata';
video.onloadedmetadata = function() { video.onloadedmetadata = function() {
setDuration(video.duration); updateOptimizeState(video.duration, file.size, isVideo);
setSize(file.size);
setIsVid(isVideo);
window.URL.revokeObjectURL(video.src); window.URL.revokeObjectURL(video.src);
}; };
video.onerror = function() { video.onerror = function() {
setDuration(0); updateOptimizeState(0, file.size, isVideo);
setSize(file.size);
setIsVid(isVideo);
}; };
video.src = window.URL.createObjectURL(file); video.src = window.URL.createObjectURL(file);
} else { } else {
setSize(file.size); updateOptimizeState(0, file.size, isVideo);
setDuration(0);
setIsVid(isVideo);
} }
} }