Files
frontend-app-authoring/src/editors/Editor.jsx
connorhaugh 4ae2d1230b feat: insert images into text editor html (#29)
This work adds the functionality that when an image is selected ineither the select image step of the image upload modal, or by using the toolbar inside tinymce, the requisite image is loaded into the settings page, and on the click of the save button, it is inserted into tinymce html.
2022-03-15 10:53:56 -04:00

87 lines
2.2 KiB
JavaScript

import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { blockTypes } from './data/constants/app';
import { thunkActions } from './data/redux';
import TextEditor from './containers/TextEditor/TextEditor';
import VideoEditor from './containers/VideoEditor/VideoEditor';
import ProblemEditor from './containers/ProblemEditor/ProblemEditor';
import EditorFooter from './components/EditorFooter';
import EditorHeader from './components/EditorHeader';
import messages from './messages';
import * as hooks from './hooks';
export const supportedEditors = {
[blockTypes.html]: TextEditor,
[blockTypes.video]: VideoEditor,
[blockTypes.problem]: ProblemEditor,
};
export const Editor = ({
courseId,
blockType,
blockId,
studioEndpointUrl,
// redux
initialize,
}) => {
hooks.initializeApp({
initialize,
data: {
blockId,
blockType,
courseId,
studioEndpointUrl,
},
});
const { editorRef, refReady, setEditorRef } = hooks.prepareEditorRef();
const EditorComponent = supportedEditors[blockType];
return (
<div className="d-flex flex-column vh-100">
<div
className="pgn__modal-fullscreen"
role="dialog"
aria-label={blockType}
>
{refReady && (
<>
<EditorHeader editorRef={editorRef} />
{(EditorComponent !== undefined)
? <EditorComponent {...{ setEditorRef, editorRef }} />
: <FormattedMessage {...messages.couldNotFindEditor} />}
<EditorFooter editorRef={editorRef} />
</>
)}
</div>
</div>
);
};
Editor.defaultProps = {
courseId: null,
blockId: null,
studioEndpointUrl: null,
};
Editor.propTypes = {
courseId: PropTypes.string,
blockType: PropTypes.string.isRequired,
blockId: PropTypes.string,
studioEndpointUrl: PropTypes.string,
// redux
initialize: PropTypes.func.isRequired,
};
export const mapStateToProps = () => ({});
export const mapDispatchToProps = {
initialize: thunkActions.app.initialize,
};
export default connect(mapStateToProps, mapDispatchToProps)(Editor);