Files
frontend-app-authoring/src/editors/containers/VideoUploadEditor/hooks.js
Daniel Valenzuela 1568067980 fix: do open editor of new xblock when duplicating (#1887)
Fixes bug where after duplicating an xblock, the editor modal of the old xblock is being open instead of the new copied xblock.
2025-05-20 17:51:42 -05:00

51 lines
1.5 KiB
JavaScript

// This 'module' self-import hack enables mocking during tests.
// See src/editors/decisions/0005-internal-editor-testability-decisions.md. The whole approach to how hooks are tested
// should be re-thought and cleaned up to avoid this pattern.
// eslint-disable-next-line import/no-self-import
import * as module from './hooks';
import { selectors, thunkActions } from '../../data/redux';
import store from '../../data/store';
import * as appHooks from '../../hooks';
export const {
navigateTo,
} = appHooks;
export const postUploadRedirect = (storeState, uploadType = 'selectedVideoUrl', onUpload = null) => {
const learningContextId = selectors.app.learningContextId(storeState);
const blockId = selectors.app.blockId(storeState);
if (onUpload) {
return (videoUrl) => {
onUpload(videoUrl, learningContextId, blockId);
};
}
return (videoUrl) => navigateTo(`/course/${learningContextId}/editor/video/${blockId}?${uploadType}=${videoUrl}`);
};
export const onVideoUpload = (uploadType, onUpload) => {
const storeState = store.getState();
return module.postUploadRedirect(storeState, uploadType, onUpload);
};
export const useUploadVideo = async ({
dispatch,
supportedFiles,
setLoadSpinner,
postUploadRedirectFunction,
}) => {
dispatch(thunkActions.video.uploadVideo({
supportedFiles,
setLoadSpinner,
postUploadRedirectFunction,
}));
};
export const useHistoryGoBack = () => (() => window.history.back());
export default {
postUploadRedirect,
onVideoUpload,
useUploadVideo,
useHistoryGoBack,
};