Skip to content

Fix multiple file options showing up (#987) #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions client/modules/IDE/components/FileNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ export class FileNode extends React.Component {
this.hideFileOptions = this.hideFileOptions.bind(this);
this.showEditFileName = this.showEditFileName.bind(this);
this.hideEditFileName = this.hideEditFileName.bind(this);
this.onBlurComponent = this.onBlurComponent.bind(this);
this.onFocusComponent = this.onFocusComponent.bind(this);

this.state = {
isOptionsOpen: false,
isEditingName: false,
isFocused: false,
};
}

onFocusComponent() {
this.setState({ isFocused: true });
}

onBlurComponent() {
this.setState({ isFocused: false });
setTimeout(() => {
if (!this.state.isFocused) {
this.hideFileOptions();
}
}, 200);
}

handleFileClick(e) {
e.stopPropagation();
if (this.props.name !== 'root' && !this.isDeleting) {
Expand Down Expand Up @@ -105,6 +121,7 @@ export class FileNode extends React.Component {
'sidebar__file-item--editing': this.state.isEditingName,
'sidebar__file-item--closed': this.props.isFolderClosed
});

return (
<div className={itemClass}>
{(() => { // eslint-disable-line
Expand Down Expand Up @@ -156,6 +173,8 @@ export class FileNode extends React.Component {
ref={(element) => { this[`fileOptions-${this.props.id}`] = element; }}
tabIndex="0"
onClick={this.toggleFileOptions}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
>
<InlineSVG src={downArrowUrl} />
</button>
Expand All @@ -171,6 +190,8 @@ export class FileNode extends React.Component {
this.props.newFile();
setTimeout(() => this.hideFileOptions(), 0);
}}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
className="sidebar__file-item-option"
>
Add File
Expand All @@ -189,6 +210,8 @@ export class FileNode extends React.Component {
this.props.newFolder();
setTimeout(() => this.hideFileOptions(), 0);
}}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
className="sidebar__file-item-option"
>
Add Folder
Expand All @@ -205,6 +228,8 @@ export class FileNode extends React.Component {
setTimeout(() => this.fileNameInput.focus(), 0);
setTimeout(() => this.hideFileOptions(), 0);
}}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
className="sidebar__file-item-option"
>
Rename
Expand All @@ -219,9 +244,8 @@ export class FileNode extends React.Component {
setTimeout(() => this.props.deleteFile(this.props.id, this.props.parentId), 100);
}
}}
onBlur={() => {
setTimeout(this.hideFileOptions, 200);
}}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
className="sidebar__file-item-option"
>
Delete
Expand Down
26 changes: 25 additions & 1 deletion client/modules/IDE/components/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ class Sidebar extends React.Component {
super(props);
this.resetSelectedFile = this.resetSelectedFile.bind(this);
this.toggleProjectOptions = this.toggleProjectOptions.bind(this);
this.onBlurComponent = this.onBlurComponent.bind(this);
this.onFocusComponent = this.onFocusComponent.bind(this);

this.state = {
isFocused: false,
};
}

onBlurComponent() {
this.setState({ isFocused: false });
setTimeout(() => {
if (!this.state.isFocused) {
this.props.closeProjectOptions();
}
}, 200);
}

onFocusComponent() {
this.setState({ isFocused: true });
}

resetSelectedFile() {
Expand Down Expand Up @@ -65,6 +84,8 @@ class Sidebar extends React.Component {
tabIndex="0"
ref={(element) => { this.sidebarOptions = element; }}
onClick={this.toggleProjectOptions}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
>
<InlineSVG src={downArrowUrl} />
</button>
Expand All @@ -76,6 +97,8 @@ class Sidebar extends React.Component {
this.props.newFolder();
setTimeout(this.props.closeProjectOptions, 0);
}}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
>
Add folder
</button>
Expand All @@ -87,7 +110,8 @@ class Sidebar extends React.Component {
this.props.newFile();
setTimeout(this.props.closeProjectOptions, 0);
}}
onBlur={() => { setTimeout(this.props.closeProjectOptions, 200); }}
onBlur={this.onBlurComponent}
onFocus={this.onFocusComponent}
>
Add file
</button>
Expand Down