make renaming files more robust--now checks to see if extension after renaming is the same

This commit is contained in:
catarak 2016-08-22 13:16:28 -04:00
parent 8713e297dd
commit de62acdaaa
2 changed files with 9 additions and 2 deletions

View file

@ -128,6 +128,7 @@ export function hideFileOptions(fileId) {
} }
export function showEditFileName(id) { export function showEditFileName(id) {
console.log('in show edit file name');
return { return {
type: ActionTypes.SHOW_EDIT_FILE_NAME, type: ActionTypes.SHOW_EDIT_FILE_NAME,
id id

View file

@ -22,7 +22,12 @@ class SidebarItem extends React.Component {
} }
validateFileName() { validateFileName() {
if (!this.props.file.name.match(/.*\.(js|css|html|json)$/)) { const oldFileExtension = this.originalFileName.match(/\.[0-9a-z]+$/i);
const newFileExtension = this.props.file.name.match(/\.[0-9a-z]+$/i);
if (oldFileExtension && !newFileExtension) {
this.props.updateFileName(this.props.file.id, this.originalFileName);
}
if (oldFileExtension && newFileExtension && oldFileExtension[0] !== newFileExtension[0]) {
this.props.updateFileName(this.props.file.id, this.originalFileName); this.props.updateFileName(this.props.file.id, this.originalFileName);
} }
} }
@ -38,7 +43,7 @@ class SidebarItem extends React.Component {
return ( return (
<li <li
className={itemClass} className={itemClass}
onBlur={() => this.props.hideFileOptions(this.props.file.id)} onBlur={() => setTimeout(() => this.props.hideFileOptions(this.props.file.id), 100)}
tabIndex={this.props.fileIndex} tabIndex={this.props.fileIndex}
onClick={() => this.props.setSelectedFile(this.props.file.id)} onClick={() => this.props.setSelectedFile(this.props.file.id)}
> >
@ -69,6 +74,7 @@ class SidebarItem extends React.Component {
<li> <li>
<a <a
onClick={() => { onClick={() => {
console.log('before show edit file name');
this.originalFileName = this.props.file.name; 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);