import React from 'react'; import PropTypes from 'prop-types'; import path from 'path'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import PageContainer from '../../services/PageContainer'; import { withUnstatedContainers } from '../UnstatedUtils'; class LinkEditModal extends React.PureComponent { constructor(props) { super(props); this.state = { show: false, isUseRelativePath: false, isUsePermanentLink: false, linkInputValue: '', labelInputValue: '', linkerType: 'mdLink', output: '[label](link)', }; this.show = this.show.bind(this); this.hide = this.hide.bind(this); this.cancel = this.cancel.bind(this); this.toggleIsUseRelativePath = this.toggleIsUseRelativePath.bind(this); this.handleChangeLinkInput = this.handleChangeLinkInput.bind(this); this.handleChangeLabelInput = this.handleChangeLabelInput.bind(this); this.handleSelecteLinkerType = this.handleSelecteLinkerType.bind(this); this.showLog = this.showLog.bind(this); this.save = this.save.bind(this); this.generateLink = this.generateLink.bind(this); this.toggleIsUsePamanentLink = this.toggleIsUsePamanentLink.bind(this); } show(editor) { const selection = editor.getDoc().getSelection(); this.setState({ show: true, labelInputValue: selection }); } cancel() { this.hide(); } hide() { this.setState({ show: false, }); } toggleIsUseRelativePath() { if (this.state.linkerType === 'growiLink') { return; } this.setState({ isUseRelativePath: !this.state.isUseRelativePath }); } renderPreview() { // TODO GW-2658 } insertLinkIntoEditor() { // TODO GW-2659 } showLog() { console.log(this.state.linkInputValue); } handleChangeLinkInput(linkValue) { this.setState({ linkInputValue: linkValue }); } handleChangeLabelInput(labelValue) { this.setState({ labelInputValue: labelValue }); } handleSelecteLinkerType(linkerType) { if (this.state.isUseRelativePath && linkerType === 'growiLink') { this.toggleIsUseRelativePath(); } this.setState({ linkerType }); } save() { if (this.props.onSave != null) { this.props.onSave(this.state.output); } this.hide(); } toggleIsUsePamanentLink() { // GW-2834 this.setState({ isUsePermanentLink: !this.state.isUsePermanentLink }); } render() { return ( Edit Links
this.handleChangeLinkInput(e.target.value)} />
{this.renderPreview} render preview
this.handleChangeLabelInput(e.target.value)} disabled={this.state.linkerType === 'growiLink'} />
); } } LinkEditModal.propTypes = { pageContainer: PropTypes.instanceOf(PageContainer).isRequired, onSave: PropTypes.func, }; /** * Wrapper component for using unstated */ const LinkEditModalWrapper = withUnstatedContainers(LinkEditModal, [PageContainer]); export default LinkEditModalWrapper;