2019-07-28 19:11:46 +00:00
|
|
|
import React from 'react'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
|
|
|
import { TextEditor } from '../components/textEditor'
|
|
|
|
import { EditorTitleContentBlock, EditorTopBarContentBlock, EditorTextContentBlock, EditorBottomBarContentBlock, EditorAttributeContentBlock } from '../components/editorContentBlock'
|
|
|
|
import { EditorEditModeRichTextOptions, EditorSubmitOptions } from '../components/editorOptionBlock'
|
|
|
|
import actions from '../actions'
|
|
|
|
import DocumentTitle from '../components/documentTitle'
|
2019-07-30 04:42:50 +00:00
|
|
|
import DocumentTitleInput from '../components/documentTitleInput'
|
2019-07-28 19:11:46 +00:00
|
|
|
import TagColorPicker from '../components/tagColorPicker'
|
2019-08-10 15:28:32 +00:00
|
|
|
import NoteMediaPicker from '../components/noteMediaPicker'
|
2019-07-30 04:42:50 +00:00
|
|
|
import MediaUploadInput from '../components/mediaUploadInput'
|
2019-07-28 19:11:46 +00:00
|
|
|
import LoadingSpinner from '../components/loadingSpinner'
|
|
|
|
|
|
|
|
const EditorEditMode = ({
|
2019-08-10 15:28:32 +00:00
|
|
|
media,
|
2019-07-28 19:11:46 +00:00
|
|
|
currentDocument,
|
|
|
|
docType,
|
|
|
|
editorState,
|
|
|
|
inputs,
|
|
|
|
userErrors,
|
|
|
|
handleKeyCommand,
|
|
|
|
onChangeEditorState,
|
|
|
|
onDocumentTitleChange,
|
|
|
|
onColorPickerInputChange,
|
|
|
|
onColorSwatchClick,
|
2019-08-10 15:28:32 +00:00
|
|
|
onClearLoadedMedia,
|
2019-07-30 04:42:50 +00:00
|
|
|
onMediaInputChange,
|
2019-08-03 02:24:24 +00:00
|
|
|
onMediaUpload,
|
2019-07-28 19:11:46 +00:00
|
|
|
cancelEdit,
|
|
|
|
onSubmitClick,
|
|
|
|
onToolButtonClick,
|
|
|
|
}) =>
|
|
|
|
<div id='editor_edit_mode' className='editor_wrapper'>
|
|
|
|
<EditorTitleContentBlock>
|
2019-07-30 04:42:50 +00:00
|
|
|
<DocumentTitleInput
|
|
|
|
input={inputs.documentTitle}
|
2019-07-28 19:11:46 +00:00
|
|
|
onChange={onDocumentTitleChange}
|
|
|
|
/>
|
|
|
|
</EditorTitleContentBlock>
|
|
|
|
<EditorTopBarContentBlock>
|
|
|
|
<EditorEditModeRichTextOptions
|
|
|
|
editorState={editorState}
|
|
|
|
onToolButtonClick={onToolButtonClick}
|
|
|
|
disabled={!currentDocument.id ? true : false}
|
|
|
|
/>
|
|
|
|
</EditorTopBarContentBlock>
|
|
|
|
<EditorTextContentBlock>
|
|
|
|
<TextEditor
|
|
|
|
editorState={editorState}
|
|
|
|
handleKeyCommand={handleKeyCommand}
|
|
|
|
onChange={onChangeEditorState}
|
|
|
|
/>
|
|
|
|
</EditorTextContentBlock>
|
|
|
|
<EditorAttributeContentBlock>
|
2019-08-10 15:28:32 +00:00
|
|
|
{docType === 'notes' &&
|
|
|
|
<NoteMediaPicker media={media} />
|
|
|
|
}
|
2019-07-28 19:11:46 +00:00
|
|
|
{docType === 'tags' &&
|
|
|
|
<TagColorPicker
|
|
|
|
input={inputs.colorPicker}
|
|
|
|
onChange={onColorPickerInputChange}
|
|
|
|
onColorSwatchClick={onColorSwatchClick}
|
|
|
|
/>
|
|
|
|
}
|
2019-08-03 02:24:24 +00:00
|
|
|
{docType === 'media' && inputs.s3Path &&
|
2019-08-10 15:28:32 +00:00
|
|
|
<div className='row'>
|
|
|
|
<div className='col-8'>File uploaded!</div>
|
|
|
|
<div className='col-2 offset-2'>
|
|
|
|
<button type='button' onClick={onClearLoadedMedia} className='btn btn-outline-info btn-sm'>
|
|
|
|
<i className={'fas fa-trash-alt'}></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-08-03 02:24:24 +00:00
|
|
|
}
|
|
|
|
{docType === 'media' && !inputs.s3Path &&
|
|
|
|
<MediaUploadInput input={inputs.uploadFile} onChange={onMediaInputChange} onUpload={onMediaUpload}/>
|
|
|
|
}
|
2019-07-28 19:11:46 +00:00
|
|
|
</EditorAttributeContentBlock>
|
|
|
|
<EditorBottomBarContentBlock>
|
|
|
|
<EditorSubmitOptions
|
|
|
|
cancelEdit={cancelEdit}
|
|
|
|
onSubmitClick={()=>onSubmitClick(currentDocument, editorState, inputs, docType)}
|
|
|
|
/>
|
|
|
|
</EditorBottomBarContentBlock>
|
|
|
|
<div id='user_errors'>
|
|
|
|
{userErrors.map(error =>
|
|
|
|
<div key={error} className='user_error_message'>{error}</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => {
|
|
|
|
return {
|
2019-08-10 15:28:32 +00:00
|
|
|
media: state.media,
|
2019-07-28 19:11:46 +00:00
|
|
|
currentDocument: state.currentDocument,
|
|
|
|
docType: state.docType,
|
|
|
|
editorState: state.editorState,
|
|
|
|
inputs: state.inputs,
|
|
|
|
userErrors: state.userErrors,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
onChangeEditorState: editorState => {
|
|
|
|
dispatch(actions.updateEditorState(editorState))
|
|
|
|
},
|
|
|
|
onDocumentTitleChange: input => {
|
|
|
|
dispatch(actions.updateDocumentTitleInput(input))
|
|
|
|
},
|
|
|
|
onColorPickerInputChange: input => {
|
|
|
|
dispatch(actions.updateColorPickerInput(input))
|
|
|
|
},
|
|
|
|
handleKeyCommand: (command, editorState) => {
|
|
|
|
dispatch(actions.handleEditorKeyCommand(editorState, command))
|
|
|
|
},
|
2019-07-30 04:42:50 +00:00
|
|
|
onMediaInputChange: input => {
|
|
|
|
dispatch(actions.updateMediaInput(input))
|
|
|
|
},
|
2019-08-03 02:24:24 +00:00
|
|
|
onMediaUpload: input => {
|
|
|
|
dispatch(actions.uploadMediaInput(input))
|
|
|
|
},
|
2019-08-10 15:28:32 +00:00
|
|
|
onClearLoadedMedia: () => {
|
|
|
|
dispatch(actions.clearLoadedMedia())
|
|
|
|
},
|
2019-07-28 19:11:46 +00:00
|
|
|
cancelEdit: () => {
|
|
|
|
dispatch(actions.cancelEdit())
|
|
|
|
},
|
|
|
|
onColorSwatchClick: (color) => {
|
|
|
|
dispatch(actions.selectColorSwatch(color))
|
|
|
|
},
|
|
|
|
onToolButtonClick: (editorState, style) => {
|
|
|
|
dispatch(actions.applyInlineStyles(editorState, style))
|
|
|
|
},
|
|
|
|
onSubmitClick: (currentDocument, editorState, inputs, docType) => {
|
|
|
|
dispatch(actions.submitDocumentEdit(currentDocument, editorState, inputs, docType))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const EditorEditModeContainer = connect(mapStateToProps, mapDispatchToProps)(EditorEditMode)
|
|
|
|
|
|
|
|
export default EditorEditModeContainer
|