|
| 1 | +/* eslint-disable import/extensions */ |
| 2 | +/* eslint-disable import/no-unresolved */ |
| 3 | +/** |
| 4 | + * This is an example component for an xblock Editor |
| 5 | + * It uses pre-existing components to handle the saving of a the result of a function into the xblock's data. |
| 6 | + * To use run npm run-script addXblock <your> |
| 7 | + */ |
| 8 | + |
| 9 | +/* eslint-disable no-unused-vars */ |
| 10 | + |
| 11 | +import React from 'react'; |
| 12 | +import { connect } from 'react-redux'; |
| 13 | +import PropTypes from 'prop-types'; |
| 14 | + |
| 15 | +import { Spinner } from '@edx/paragon'; |
| 16 | +import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; |
| 17 | + |
| 18 | +import EditorContainer from '../EditorContainer'; |
| 19 | +import * as module from '.'; |
| 20 | +import { actions, selectors } from '../../data/redux'; |
| 21 | +import { RequestKeys } from '../../data/constants/requests'; |
| 22 | + |
| 23 | +export const hooks = { |
| 24 | + getContent: () => ({ |
| 25 | + some: 'content', |
| 26 | + }), |
| 27 | +}; |
| 28 | + |
| 29 | +export const thumbEditor = ({ |
| 30 | + onClose, |
| 31 | + // redux |
| 32 | + blockValue, |
| 33 | + lmsEndpointUrl, |
| 34 | + blockFailed, |
| 35 | + blockFinished, |
| 36 | + initializeEditor, |
| 37 | + exampleValue, |
| 38 | + // inject |
| 39 | + intl, |
| 40 | +}) => ( |
| 41 | + <EditorContainer |
| 42 | + getContent={module.hooks.getContent} |
| 43 | + onClose={onClose} |
| 44 | + > |
| 45 | + <div> |
| 46 | + {exampleValue} |
| 47 | + </div> |
| 48 | + <div className="editor-body h-75 overflow-auto"> |
| 49 | + {!blockFinished |
| 50 | + ? ( |
| 51 | + <div className="text-center p-6"> |
| 52 | + <Spinner |
| 53 | + animation="border" |
| 54 | + className="m-3" |
| 55 | + // Use a messages.js file for intl messages. |
| 56 | + screenreadertext={intl.formatMessage('Loading Spinner')} |
| 57 | + /> |
| 58 | + </div> |
| 59 | + ) |
| 60 | + : ( |
| 61 | + <p> |
| 62 | + Your Editor Goes here. |
| 63 | + You can get at the xblock data with the blockValue field. |
| 64 | + here is what is in your xblock: {JSON.stringify(blockValue)} |
| 65 | + </p> |
| 66 | + )} |
| 67 | + </div> |
| 68 | + </EditorContainer> |
| 69 | +); |
| 70 | +thumbEditor.defaultProps = { |
| 71 | + blockValue: null, |
| 72 | + lmsEndpointUrl: null, |
| 73 | +}; |
| 74 | +thumbEditor.propTypes = { |
| 75 | + onClose: PropTypes.func.isRequired, |
| 76 | + // redux |
| 77 | + blockValue: PropTypes.shape({ |
| 78 | + data: PropTypes.shape({ data: PropTypes.string }), |
| 79 | + }), |
| 80 | + lmsEndpointUrl: PropTypes.string, |
| 81 | + blockFailed: PropTypes.bool.isRequired, |
| 82 | + blockFinished: PropTypes.bool.isRequired, |
| 83 | + initializeEditor: PropTypes.func.isRequired, |
| 84 | + // inject |
| 85 | + intl: intlShape.isRequired, |
| 86 | +}; |
| 87 | + |
| 88 | +export const mapStateToProps = (state) => ({ |
| 89 | + blockValue: selectors.app.blockValue(state), |
| 90 | + lmsEndpointUrl: selectors.app.lmsEndpointUrl(state), |
| 91 | + blockFailed: selectors.requests.isFailed(state, { requestKey: RequestKeys.fetchBlock }), |
| 92 | + blockFinished: selectors.requests.isFinished(state, { requestKey: RequestKeys.fetchBlock }), |
| 93 | + // TODO fill with redux state here if needed |
| 94 | + exampleValue: selectors.game.exampleValue(state), |
| 95 | +}); |
| 96 | + |
| 97 | +export const mapDispatchToProps = { |
| 98 | + initializeEditor: actions.app.initializeEditor, |
| 99 | + // TODO fill with dispatches here if needed |
| 100 | +}; |
| 101 | + |
| 102 | +export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(thumbEditor)); |
0 commit comments