|
|
|
@ -19,20 +19,23 @@ const MAX_FILE_SIZE = 200
|
|
|
|
|
let noUploads = true
|
|
|
|
|
function VideoUploadList (props) {
|
|
|
|
|
|
|
|
|
|
// const [videoes, setVideoes] = useState([]);
|
|
|
|
|
// const [videos, setvideos] = useState([]);
|
|
|
|
|
const [state, dispatch] = useReducer(reducer, initialState);
|
|
|
|
|
const theme = useContext(ThemeContext)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Chrome removed support for custom message in ver 51
|
|
|
|
|
// https://stackoverflow.com/questions/38879742/is-it-possible-to-display-a-custom-message-in-the-beforeunload-popup
|
|
|
|
|
window.addEventListener("beforeunload", beforeunload);
|
|
|
|
|
|
|
|
|
|
// window.onbeforeunload = beforeunload
|
|
|
|
|
return () => {
|
|
|
|
|
uploader = null;
|
|
|
|
|
// window.onbeforeunload = null;
|
|
|
|
|
window.removeEventListener("beforeunload", beforeunload);
|
|
|
|
|
}
|
|
|
|
|
}, [])
|
|
|
|
|
// TODO 闭包!
|
|
|
|
|
noUploads = (!state.videoes || state.videoes.length == 0);
|
|
|
|
|
noUploads = (!state.videos || state.videos.length == 0);
|
|
|
|
|
function beforeunload(e) {
|
|
|
|
|
if (noUploads) {
|
|
|
|
|
return true;
|
|
|
|
@ -62,7 +65,7 @@ function VideoUploadList (props) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let gotTheSameFileName = false;
|
|
|
|
|
state.videoes.some((item) => {
|
|
|
|
|
state.videos.some((item) => {
|
|
|
|
|
if (item.name == file.name) {
|
|
|
|
|
gotTheSameFileName = true;
|
|
|
|
|
return true;
|
|
|
|
@ -86,7 +89,7 @@ function VideoUploadList (props) {
|
|
|
|
|
addFileSuccess: (uploadInfo) => {
|
|
|
|
|
const file = uploadInfo.file
|
|
|
|
|
console.log('addFileSuccess', uploadInfo)
|
|
|
|
|
// const newVideoes = [...videoes, {
|
|
|
|
|
// const newvideos = [...videos, {
|
|
|
|
|
// name: file.name,
|
|
|
|
|
// size: file.size,
|
|
|
|
|
// type: file.type,
|
|
|
|
@ -96,7 +99,7 @@ function VideoUploadList (props) {
|
|
|
|
|
// videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2"
|
|
|
|
|
// loaded: 0
|
|
|
|
|
// }]
|
|
|
|
|
// setVideoes(newVideoes)
|
|
|
|
|
// setvideos(newvideos)
|
|
|
|
|
|
|
|
|
|
// files.push(file)
|
|
|
|
|
clearInput()
|
|
|
|
@ -107,7 +110,7 @@ function VideoUploadList (props) {
|
|
|
|
|
var progressPercent = Math.ceil(progress * 100)
|
|
|
|
|
|
|
|
|
|
// let _index = -1;
|
|
|
|
|
// videoes.some((item, index) => {
|
|
|
|
|
// videos.some((item, index) => {
|
|
|
|
|
// // addFileSuccess的时候没有fileHash
|
|
|
|
|
// // if (uploadInfo.fileHash == item.fileHash) {
|
|
|
|
|
// if (uploadInfo.file.name == item.name) {
|
|
|
|
@ -119,7 +122,7 @@ function VideoUploadList (props) {
|
|
|
|
|
// TODO 这里不用reducer,会出现state被重置的问题
|
|
|
|
|
|
|
|
|
|
// if (_index == -1) {
|
|
|
|
|
// const newVideoes = [...videoes, {
|
|
|
|
|
// const newvideos = [...videos, {
|
|
|
|
|
// name: file.name,
|
|
|
|
|
// size: file.size,
|
|
|
|
|
// type: file.type,
|
|
|
|
@ -129,12 +132,12 @@ function VideoUploadList (props) {
|
|
|
|
|
// videoId: uploadInfo.videoId, // "719b82c875c34ac39f94feb145d25ad2"
|
|
|
|
|
// loaded: progressPercent
|
|
|
|
|
// }]
|
|
|
|
|
// setVideoes(newVideoes)
|
|
|
|
|
// setvideos(newvideos)
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // exercise_questions : update(prevState.exercise_questions, {[index]: { isNew: {$set: false}}})
|
|
|
|
|
// setVideoes(update(videoes, {[_index]: { loaded: {$set: progressPercent}}}))
|
|
|
|
|
// setvideos(update(videos, {[_index]: { loaded: {$set: progressPercent}}}))
|
|
|
|
|
|
|
|
|
|
dispatch({type: 'updateProgress', uploadInfo, progressPercent})
|
|
|
|
|
},
|
|
|
|
@ -179,14 +182,14 @@ function VideoUploadList (props) {
|
|
|
|
|
uploader.deleteFile(index)
|
|
|
|
|
if (isSuccess) {
|
|
|
|
|
// uploader.deleteFile(index)
|
|
|
|
|
// deleteVideoInCloud(username, state.videoes[index].videoId)
|
|
|
|
|
// deleteVideoInCloud(username, state.videos[index].videoId)
|
|
|
|
|
} else {
|
|
|
|
|
// uploader.cancelFile(index)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearInput()
|
|
|
|
|
dispatch({type: 'removeVideo', index})
|
|
|
|
|
// setVideoes([...videoes.splice(index, 1)])
|
|
|
|
|
// setvideos([...videos.splice(index, 1)])
|
|
|
|
|
}
|
|
|
|
|
// uploader.deleteFile(index);
|
|
|
|
|
function cancelUpload(index, isSuccess) {
|
|
|
|
@ -201,13 +204,13 @@ function VideoUploadList (props) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
function onPublish() {
|
|
|
|
|
if (state.videoes.length == 0) {
|
|
|
|
|
if (state.videos.length == 0) {
|
|
|
|
|
showNotification('请先上传视频')
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const publishUrl = `/users/${username}/videos/batch_publish.json`
|
|
|
|
|
axios.post(publishUrl, {
|
|
|
|
|
videos: state.videoes.map(item => {
|
|
|
|
|
videos: state.videos.map(item => {
|
|
|
|
|
return {
|
|
|
|
|
video_id: item.videoId,
|
|
|
|
|
// todo
|
|
|
|
@ -217,7 +220,7 @@ function VideoUploadList (props) {
|
|
|
|
|
}).then((response) => {
|
|
|
|
|
// to success page
|
|
|
|
|
if (response.data.status == 0) {
|
|
|
|
|
history.push(`/users/${username}/videoes/success`)
|
|
|
|
|
history.push(`/users/${username}/videos/success`)
|
|
|
|
|
}
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
@ -334,7 +337,7 @@ function VideoUploadList (props) {
|
|
|
|
|
className="mb26"
|
|
|
|
|
separator=" > "
|
|
|
|
|
items={[
|
|
|
|
|
{ to: `/users/${username}/videoes`, name: '视频'},
|
|
|
|
|
{ to: `/users/${username}/videos`, name: '视频'},
|
|
|
|
|
{ name: '上传'}
|
|
|
|
|
]}
|
|
|
|
|
></CBreadcrumb>
|
|
|
|
@ -363,7 +366,7 @@ function VideoUploadList (props) {
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
{state.videoes.map((item, vIndex) => {
|
|
|
|
|
{state.videos.map((item, vIndex) => {
|
|
|
|
|
return (
|
|
|
|
|
<VideoUpload {...props} {...item} className=""
|
|
|
|
|
cancelUpload={cancelUpload}
|
|
|
|
@ -374,13 +377,13 @@ function VideoUploadList (props) {
|
|
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
{state.videoes && state.videoes.length === MAX_FILE_COUNT &&
|
|
|
|
|
{state.videos && state.videos.length === MAX_FILE_COUNT &&
|
|
|
|
|
<div className="uploadTip">
|
|
|
|
|
<i className="iconfont icon-tishi" style={{color: '#FF6F6F', verticalAlign: 'text-bottom'}}></i>
|
|
|
|
|
<span>单次最多支持3个视频文件上传</span>
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
|
|
{(!noUploads && state.videoes.length < MAX_FILE_COUNT) && <ActionBtn className="publishBtn" onClick={() => document.getElementById('fileUpload').click()}
|
|
|
|
|
{(!noUploads && state.videos.length < MAX_FILE_COUNT) && <ActionBtn className="publishBtn" onClick={() => document.getElementById('fileUpload').click()}
|
|
|
|
|
>继续添加</ActionBtn>}
|
|
|
|
|
|
|
|
|
|
<div className={`description ${noUploads ? 'noUploads' : ''}`}>
|
|
|
|
@ -391,7 +394,7 @@ function VideoUploadList (props) {
|
|
|
|
|
|
|
|
|
|
{!noUploads && <React.Fragment>
|
|
|
|
|
|
|
|
|
|
{/* {(state.videoes.length < MAX_FILE_COUNT) && <Button type="primary" icon="plus-square"
|
|
|
|
|
{/* {(state.videos.length < MAX_FILE_COUNT) && <Button type="primary" icon="plus-square"
|
|
|
|
|
onClick={() => { document.getElementById('fileUpload').click()}}
|
|
|
|
|
className="fr addVideoBtn"
|
|
|
|
|
>
|
|
|
|
|