Skip to content

Commit

Permalink
feat(mux-uploader): Support Upchunk's attempt and chunkSuccess events.
Browse files Browse the repository at this point in the history
  • Loading branch information
clearlyTHUYDOAN authored and cjpillsbury committed Jul 21, 2022
1 parent 8745784 commit 739a88e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/mux-uploader-react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type MuxUploaderProps = {
};
children?: React.ReactNode;
formatProgress?: (percent: number) => string;
onAttempt?: EventListener;
onChunkSuccess?: EventListener;
onError?: EventListener;
onProgress?: EventListener;
onSuccess?: EventListener;
Expand Down Expand Up @@ -61,9 +63,12 @@ const useUploader = (
React.MutableRefObject<MuxUploaderElement | null> | null | undefined,
props: MuxUploaderProps
) => {
const { onError, onProgress, onSuccess, formatProgress, endpoint, ...remainingProps } = props;
const { onAttempt, onChunkSuccess, onError, onProgress, onSuccess, formatProgress, endpoint, ...remainingProps } =
props;
useObjectPropEffect('endpoint', endpoint, ref);
useObjectPropEffect('formatProgress', formatProgress, ref);
useEventCallbackEffect('attempt', ref, onAttempt);
useEventCallbackEffect('chunkSuccess', ref, onChunkSuccess);
useEventCallbackEffect('error', ref, onError);
useEventCallbackEffect('progress', ref, onProgress);
useEventCallbackEffect('success', ref, onSuccess);
Expand Down
8 changes: 8 additions & 0 deletions packages/mux-uploader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ class MuxUploaderElement extends HTMLElement {
file: evt.detail,
});

upload.on('attempt', ({ detail }) => {
this.dispatchEvent(new CustomEvent('attempt', detail));
});

upload.on('chunkSuccess', ({ detail }) => {
this.dispatchEvent(new CustomEvent('chunkSuccess', detail));
});

upload.on('error', (err) => {
const errorMessage = 'An error has occurred';

Expand Down

0 comments on commit 739a88e

Please sign in to comment.