mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added envents props
This commit is contained in:
parent
8e4b1a12e2
commit
f8cd98d372
@ -6,16 +6,48 @@ import { Icons } from "components/Icons"
|
||||
export default (props) => {
|
||||
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) => {
|
||||
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({
|
||||
message: "Could not upload file",
|
||||
description: err.message
|
||||
title: "Could not upload file",
|
||||
description: err
|
||||
}, {
|
||||
type: "error"
|
||||
})
|
||||
|
||||
return handleOnError(req.file.uid, err)
|
||||
})
|
||||
|
||||
if (typeof props.ctx?.onUpdateItem === "function") {
|
||||
@ -23,14 +55,12 @@ export default (props) => {
|
||||
}
|
||||
|
||||
if (typeof props.onUploadDone === "function") {
|
||||
if (props.multiple) {
|
||||
await props.onUploadDone(response)
|
||||
} else {
|
||||
await props.onUploadDone(response)
|
||||
}
|
||||
await props.onUploadDone(response)
|
||||
}
|
||||
|
||||
setUploading(false)
|
||||
|
||||
return handleOnSuccess(req.file.uid, response)
|
||||
}
|
||||
|
||||
return <Upload
|
||||
|
Loading…
x
Reference in New Issue
Block a user