import React from 'react'; import PropTypes from 'prop-types'; import { Card, NgIf, Icon, EventEmitter } from '../../components/'; import { pathBuilder } from '../../helpers/'; @EventEmitter export class NewThing extends React.Component { constructor(props){ super(props); this.state = { name: null, type: null, message: null, icon: null } } onNew(type){ 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.setState({icon: 'loading'}) this.props.emit('file.create', pathBuilder(this.props.path, this.state.name, this.state.type), this.state.type) .then((ok) => this.props.emit('file.refresh', this.props.path)) .then((ok) => { this.onDelete(); return Promise.resolve('ok'); }) .catch(err => { if(err && err.code === 'CANCELLED'){ return } this.setState({message: err.message, icon: 'error'}) }) } } onSortUpdate(e){ this.props.onSortUpdate(e.target.value); } render(){ return (
New File New Directory
this.setState({name: e.target.value})} value={this.state.name} style={{outline: 'none'}} type="text" autoFocus/>
{this.state.message}
) }; } NewThing.PropTypes = { accessRight: PropTypes.obj, onCreate: PropTypes.func.isRequired, onSortUpdate: PropTypes.func.isRequired, sort: PropTypes.string.isRequired, }