import React from 'react'; import PropTypes from 'prop-types'; import { Card, NgIf, Icon, EventEmitter } from '../../components/'; import { pathBuilder } from '../../helpers/'; import "./thing.scss"; @EventEmitter export class NewThing extends React.Component { constructor(props){ super(props); this.state = { name: null, type: null, message: null, icon: null }; this._onEscapeKeyPress = (e) => { if(e.keyCode === 27) this.onDelete(); } } componentDidMount(){ window.addEventListener('keydown', this._onEscapeKeyPress); } componentWillUnmount(){ window.removeEventListener('keydown', this._onEscapeKeyPress); } onNew(type){ if(this.state.type === type){ this.onDelete(); }else{ this.setState({type: type, name: '', icon: type}); } } onDelete(){ this.setState({type: null, name: null, icon: null}); } onSave(e){ e.preventDefault(); if(this.state.name !== null){ this.props.emit('file.create', pathBuilder(this.props.path, this.state.name, this.state.type), this.state.type); this.onDelete(); } } onSortUpdate(e){ this.props.onSortUpdate(e.target.value); } render(){ return (
New File New Directory
this.setState({name: e.target.value})} value={this.state.name} type="text" autoFocus/>
{this.state.message}
); }; } NewThing.PropTypes = { accessRight: PropTypes.obj, onCreate: PropTypes.func.isRequired, onSortUpdate: PropTypes.func.isRequired, sort: PropTypes.string.isRequired }