import React from 'react'; import PropTypes from 'prop-types'; import { Card, NgIf, Icon, EventEmitter, Dropdown, DropdownButton, DropdownList, DropdownItem } 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, search: "ServiceWorker" in window ? "" : 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(); } } onViewChange(e){ this.props.onViewUpdate(); } onSortChange(e){ this.props.onSortUpdate(e); } render(){ return (
New File New Directory Sort By Type Sort By Date Sort By Name
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 };