mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 19:44:15 +00:00
Merge pull request #102 from ragestudio/uploads-progress_bar
Uploads progress bar
This commit is contained in:
commit
34b2af6c7a
@ -6,16 +6,48 @@ import { Icons } from "components/Icons"
|
|||||||
export default (props) => {
|
export default (props) => {
|
||||||
const [uploading, setUploading] = React.useState(false)
|
const [uploading, setUploading] = React.useState(false)
|
||||||
|
|
||||||
|
const handleOnStart = (file_uid, file) => {
|
||||||
|
if (typeof props.onStart === "function") {
|
||||||
|
props.onStart(file_uid, file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOnProgress = (file_uid, progress) => {
|
||||||
|
if (typeof props.onProgress === "function") {
|
||||||
|
props.onProgress(file_uid, progress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOnError = (file_uid, error) => {
|
||||||
|
if (typeof props.onError === "function") {
|
||||||
|
props.onError(file_uid, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOnSuccess = (file_uid, response) => {
|
||||||
|
if (typeof props.onSuccess === "function") {
|
||||||
|
props.onSuccess(file_uid, response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleUpload = async (req) => {
|
const handleUpload = async (req) => {
|
||||||
setUploading(true)
|
setUploading(true)
|
||||||
|
|
||||||
const response = await app.cores.remoteStorage.uploadFile(req.file).catch((err) => {
|
handleOnStart(req.file.uid, req.file)
|
||||||
|
|
||||||
|
const response = await app.cores.remoteStorage.uploadFile(req.file, {
|
||||||
|
onProgress: (file, progress) => {
|
||||||
|
return handleOnProgress(file.uid, progress)
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
app.notification.new({
|
app.notification.new({
|
||||||
message: "Could not upload file",
|
title: "Could not upload file",
|
||||||
description: err.message
|
description: err
|
||||||
}, {
|
}, {
|
||||||
type: "error"
|
type: "error"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return handleOnError(req.file.uid, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (typeof props.ctx?.onUpdateItem === "function") {
|
if (typeof props.ctx?.onUpdateItem === "function") {
|
||||||
@ -23,14 +55,12 @@ export default (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof props.onUploadDone === "function") {
|
if (typeof props.onUploadDone === "function") {
|
||||||
if (props.multiple) {
|
await props.onUploadDone(response)
|
||||||
await props.onUploadDone(response)
|
|
||||||
} else {
|
|
||||||
await props.onUploadDone(response)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
|
|
||||||
|
return handleOnSuccess(req.file.uid, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Upload
|
return <Upload
|
||||||
|
@ -207,7 +207,7 @@ export default class RemoteStorage extends Core {
|
|||||||
console.error("[Uploader] Error", message)
|
console.error("[Uploader] Error", message)
|
||||||
|
|
||||||
if (typeof onError === "function") {
|
if (typeof onError === "function") {
|
||||||
onError(message)
|
onError(file, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
reject(message)
|
reject(message)
|
||||||
@ -217,7 +217,7 @@ export default class RemoteStorage extends Core {
|
|||||||
//console.debug(`[Uploader] Progress: ${percentProgress}%`)
|
//console.debug(`[Uploader] Progress: ${percentProgress}%`)
|
||||||
|
|
||||||
if (typeof onProgress === "function") {
|
if (typeof onProgress === "function") {
|
||||||
onProgress(percentProgress)
|
onProgress(file, percentProgress)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ export default class RemoteStorage extends Core {
|
|||||||
console.debug("[Uploader] Finish", data)
|
console.debug("[Uploader] Finish", data)
|
||||||
|
|
||||||
if (typeof onFinish === "function") {
|
if (typeof onFinish === "function") {
|
||||||
onFinish(data)
|
onFinish(file, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(data)
|
resolve(data)
|
||||||
|
@ -207,6 +207,19 @@ const FileListItem = (props) => {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<div className={classnames(
|
||||||
|
"fileListItem_progress",
|
||||||
|
{
|
||||||
|
["hidden"]: !isUploading,
|
||||||
|
}
|
||||||
|
)}>
|
||||||
|
<antd.Progress
|
||||||
|
percent={props.track.progress ?? 0}
|
||||||
|
status={props.track.status === "error" ? "exception" : (props.track.progress === 100 ? "success" : "active")}
|
||||||
|
showInfo={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="fileListItem_cover">
|
<div className="fileListItem_cover">
|
||||||
<img
|
<img
|
||||||
src={props.track.cover ?? props.track?.thumbnail}
|
src={props.track.cover ?? props.track?.thumbnail}
|
||||||
|
@ -136,6 +136,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fileListItem_progress {
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
.ant-progress-line {
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
|
||||||
|
width: 40%;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.hidden {
|
||||||
|
animation: hide 0.2s ease-in-out forwards;
|
||||||
|
animation-delay: 2s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.fileListItem_loadingIcon {
|
.fileListItem_loadingIcon {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -155,6 +182,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.fileListItem_cover {
|
.fileListItem_cover {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
@ -337,8 +366,22 @@
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
|
|
||||||
background-color: black;
|
background-color: black;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes hide {
|
||||||
|
0% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
99% {
|
||||||
|
opacity: 0;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
width: 0px;
|
||||||
|
}
|
||||||
}
|
}
|
@ -161,9 +161,23 @@ export default class PlaylistCreatorSteps extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleFileProgress = (file, progress) => {
|
||||||
|
const trackList = this.state.trackList
|
||||||
|
|
||||||
|
const track = trackList.find((track) => track.uid === file.uid)
|
||||||
|
|
||||||
|
if (track) {
|
||||||
|
track.progress = progress
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
trackList
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleUploadTrack = async (req) => {
|
handleUploadTrack = async (req) => {
|
||||||
const response = await app.cores.remoteStorage.uploadFile(req.file, {
|
const response = await app.cores.remoteStorage.uploadFile(req.file, {
|
||||||
timeout: 2000
|
onProgress: this.handleFileProgress
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
antd.message.error(error)
|
antd.message.error(error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user