import React, { Component, PropTypes } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import SplitPane from 'react-split-pane'; import Button from 'react-toolbox/lib/button'; import { ScrollSync, ScrollSyncPane } from '../ScrollSync'; import ControlPane from '../ControlPanel/ControlPane'; import PreviewPane from '../PreviewPane/PreviewPane'; import Toolbar from './EntryEditorToolbar'; import styles from './EntryEditor.css'; const PREVIEW_VISIBLE = 'cms.preview-visible'; class EntryEditor extends Component { state = { showEventBlocker: false, previewVisible: localStorage.getItem(PREVIEW_VISIBLE) !== "false", }; handleSplitPaneDragStart = () => { this.setState({ showEventBlocker: true }); }; handleSplitPaneDragFinished = () => { this.setState({ showEventBlocker: false }); }; handleOnPersist = () => { this.controlPaneRef.validate(); this.props.onPersist(); }; handleTogglePreview = () => { const newPreviewVisible = !this.state.previewVisible; this.setState({ previewVisible: newPreviewVisible }); localStorage.setItem(PREVIEW_VISIBLE, newPreviewVisible); }; render() { const { collection, entry, fields, fieldsMetaData, fieldsErrors, getAsset, onChange, onValidate, onAddAsset, onRemoveAsset, onCancelEdit, } = this.props; const controlClassName = `${ styles.controlPane } ${ this.state.showEventBlocker && styles.blocker }`; const previewClassName = `${ styles.previewPane } ${ this.state.showEventBlocker && styles.blocker }`; const editor = (
this.controlPaneRef = c} // eslint-disable-line />
); const editorWithPreview = (
{editor}
); return (
{ this.state.previewVisible ? editorWithPreview : editor }
); } } EntryEditor.propTypes = { collection: ImmutablePropTypes.map.isRequired, entry: ImmutablePropTypes.map.isRequired, fields: ImmutablePropTypes.list.isRequired, fieldsMetaData: ImmutablePropTypes.map.isRequired, fieldsErrors: ImmutablePropTypes.map.isRequired, getAsset: PropTypes.func.isRequired, onAddAsset: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired, onValidate: PropTypes.func.isRequired, onPersist: PropTypes.func.isRequired, onRemoveAsset: PropTypes.func.isRequired, onCancelEdit: PropTypes.func.isRequired, }; export default EntryEditor;