added envents props

This commit is contained in:
SrGooglo 2023-06-01 17:09:49 +00:00
parent 8e4b1a12e2
commit f8cd98d372

View File

@ -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