import React from 'react'; import { gettext } from '../../../utils/constants'; import { Button, Modal, ModalHeader, Input, ModalBody, ModalFooter, Form, FormGroup, Label, Col, FormText } from 'reactstrap'; class CreateFileForder extends React.Component { constructor(props) { super(props); this.state = { parentPath: '', childName: '' }; this.newInput = React.createRef() } handleChange = (e) => { this.setState({ childName: e.target.value, }) } handleSubmit = () => { let path = this.state.parentPath + this.state.childName if (this.props.isFile) { this.props.onAddFile(path); } else { this.props.onAddFolder(path); } } handleKeyPress = (e) => { if (e.key === 'Enter') { this.handleSubmit(); } } toggle = () => { if (this.props.isFile) { this.props.addFileCancel(); } else { this.props.addFolderCancel(); } } componentWillMount() { this.changeState(this.props.isFile); } componentDidMount() { if (this.props.currentNode.path === "/") { this.setState({parentPath: this.props.currentNode.path}); } else { this.setState({parentPath: this.props.currentNode.path + "/"}); } this.newInput.focus(); this.newInput.setSelectionRange(0,0); } componentWillReceiveProps(nextProps) { this.changeState(nextProps.isFile); } changeState(isFile) { if (isFile) { this.setState({childName: '.md'}); } else{ this.setState({childName: ""}); } } render() { return ( {this.props.isFile ? gettext("New File") : gettext("New Folder")}
{this.state.parentPath} {this.newInput = input}} id="fileName" placeholder={gettext("newName")} value={this.state.childName} onChange={this.handleChange}/>
) } } export default CreateFileForder;