add rename validation

This commit is contained in:
catarak 2016-08-03 17:42:58 -04:00
parent 443a9f57d5
commit 8c4003bb17

View file

@ -8,6 +8,7 @@ class SidebarItem extends React.Component {
super(props); super(props);
this.handleKeyPress = this.handleKeyPress.bind(this); this.handleKeyPress = this.handleKeyPress.bind(this);
this.handleFileNameChange = this.handleFileNameChange.bind(this); this.handleFileNameChange = this.handleFileNameChange.bind(this);
this.validateFileName = this.validateFileName.bind(this);
} }
handleFileNameChange(event) { handleFileNameChange(event) {
@ -21,6 +22,12 @@ class SidebarItem extends React.Component {
} }
} }
validateFileName() {
if (!this.props.file.name.match(/.*\.(js|css|html|json)$/)) {
this.props.updateFileName(this.props.file.id, this.originalFileName);
}
}
render() { render() {
let itemClass = classNames({ let itemClass = classNames({
'sidebar__file-item': true, 'sidebar__file-item': true,
@ -45,7 +52,10 @@ class SidebarItem extends React.Component {
value={this.props.file.name} value={this.props.file.name}
onChange={this.handleFileNameChange} onChange={this.handleFileNameChange}
ref="fileNameInput" ref="fileNameInput"
onBlur={() => this.props.hideEditFileName(this.props.file.id)} onBlur={() => {
this.validateFileName();
this.props.hideEditFileName(this.props.file.id);
}}
onKeyPress={this.handleKeyPress} onKeyPress={this.handleKeyPress}
/> />
<a <a
@ -59,6 +69,7 @@ class SidebarItem extends React.Component {
<li> <li>
<a <a
onClick={() => { onClick={() => {
this.originalFileName = this.props.file.name;
this.props.showEditFileName(this.props.file.id); this.props.showEditFileName(this.props.file.id);
setTimeout(() => this.refs.fileNameInput.focus(), 0); setTimeout(() => this.refs.fileNameInput.focus(), 0);
}} }}