-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added onSuccessAction prop to Upload Widget #487
Changes from 2 commits
8283942
3f3f2e4
9d80aff
3aa13fc
a434d39
8e8349f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
import { triggerOnIdle } from '../../lib/util'; | ||
|
||
import { | ||
CldUploadEventAction, | ||
CldUploadEventCallback, | ||
CldUploadWidgetCloudinaryInstance, | ||
CldUploadWidgetProps, | ||
|
@@ -57,6 +58,8 @@ const CldUploadWidget = ({ | |
|
||
const signed = !!signatureEndpoint; | ||
|
||
const { onSuccessAction } = props; | ||
|
||
const [error, setError] = useState<CloudinaryUploadWidgetError | undefined>(undefined); | ||
const [results, setResults] = useState<CloudinaryUploadWidgetResults | undefined>(undefined); | ||
const [isScriptLoading, setIsScriptLoading] = useState(true); | ||
|
@@ -251,7 +254,7 @@ const CldUploadWidget = ({ | |
} | ||
|
||
if ( typeof uploadResult?.event === 'string' ) { | ||
if ( WIDGET_WATCHED_EVENTS.includes(uploadResult?.event) ) { | ||
if ( WIDGET_WATCHED_EVENTS.includes(uploadResult?.event as string) ) { | ||
setResults(uploadResult); | ||
} | ||
|
||
|
@@ -264,6 +267,13 @@ const CldUploadWidget = ({ | |
...instanceMethods | ||
}); | ||
} | ||
|
||
const widgetEventAction = `${widgetEvent}Action` as keyof typeof props; | ||
|
||
if ( widgetEventAction && typeof props[widgetEventAction] === 'function' ) { | ||
const action = props[widgetEventAction] as CldUploadEventAction; | ||
uploadResult.event === 'success' && action(uploadResult); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can remove the 'success' check here right? as long as the function exists and its under the watched events, which at this point i believe both should be true, we should be good, right? |
||
} | ||
} | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,20 @@ export interface CldUploadWidgetProps { | |
options?: CloudinaryUploadWidgetOptions; | ||
signatureEndpoint?: URL | RequestInfo; | ||
uploadPreset?: string; | ||
onSuccessAction?: CldUploadEventAction; | ||
onUploadAction?: CldUploadEventAction; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
onAbortAction?: CldUploadEventAction; | ||
onBatchCancelledAction?: CldUploadEventAction; | ||
onCloseAction?: CldUploadEventAction; | ||
onDisplayChangedAction?: CldUploadEventAction; | ||
onPublicIdAction?: CldUploadEventAction; | ||
onQueuesEndAction?: CldUploadEventAction; | ||
onQueuesStartAction?: CldUploadEventAction; | ||
onRetryAction?: CldUploadEventAction; | ||
onShowCompletedAction?: CldUploadEventAction; | ||
onSourceChangedAction?: CldUploadEventAction; | ||
onTagsAction?: CldUploadEventAction; | ||
onUploadAddedAction?: CldUploadEventAction; | ||
} | ||
|
||
export type CldUploadWidgetPropsChildren = { | ||
|
@@ -45,6 +59,7 @@ export type CldUploadWidgetPropsChildren = { | |
} & CloudinaryUploadWidgetInstanceMethods; | ||
|
||
export type CldUploadEventCallback = (results: CloudinaryUploadWidgetResults, widget: CldUploadEventCallbackWidget) => void; | ||
export type CldUploadEventAction = (results: CloudinaryUploadWidgetResults) => void; | ||
export type CldUploadEventCallbackNoOptions = (results: CloudinaryUploadWidgetResults, widget: CldUploadWidgetWidgetInstance) => void; | ||
export type CldUploadEventCallbackWidgetOnly = (widget: CldUploadWidgetWidgetInstance) => void; | ||
export type CldUploadEventCallbackError = (error: CloudinaryUploadWidgetError, widget: CldUploadEventCallbackWidget) => void; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont think this is needed anymore