Skip to content

Commit 9ef9075

Browse files
authored
Merge pull request #1602 from neelesh7singh/add-new-file/folder-bugfix
Add new file/folder bugfix
2 parents b7d17a0 + c4e6836 commit 9ef9075

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

client/modules/IDE/components/NewFileModal.jsx

+13
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,23 @@ class NewFileModal extends React.Component {
2020
constructor(props) {
2121
super(props);
2222
this.focusOnModal = this.focusOnModal.bind(this);
23+
this.handleOutsideClick = this.handleOutsideClick.bind(this);
2324
}
2425

2526
componentDidMount() {
2627
this.focusOnModal();
28+
document.addEventListener('click', this.handleOutsideClick, false);
29+
}
30+
31+
componentWillUnmount() {
32+
document.removeEventListener('click', this.handleOutsideClick, false);
33+
}
34+
35+
handleOutsideClick(e) {
36+
// ignore clicks on the component itself
37+
if (e.path.includes(this.modal)) return;
38+
39+
this.props.closeNewFileModal();
2740
}
2841

2942
focusOnModal() {

client/modules/IDE/components/NewFolderModal.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,25 @@ import NewFolderForm from './NewFolderForm';
88
import ExitIcon from '../../../images/exit.svg';
99

1010
class NewFolderModal extends React.Component {
11+
constructor(props) {
12+
super(props);
13+
this.handleOutsideClick = this.handleOutsideClick.bind(this);
14+
}
15+
1116
componentDidMount() {
1217
this.newFolderModal.focus();
18+
document.addEventListener('click', this.handleOutsideClick, false);
19+
}
20+
21+
componentWillUnmount() {
22+
document.removeEventListener('click', this.handleOutsideClick, false);
23+
}
24+
25+
handleOutsideClick(e) {
26+
// ignore clicks on the component itself
27+
if (e.path.includes(this.newFolderModal)) return;
28+
29+
this.props.closeModal();
1330
}
1431

1532
render() {

client/modules/IDE/reducers/ide.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ const ide = (state = initialState, action) => {
4040
case ActionTypes.CONSOLE_EVENT:
4141
return Object.assign({}, state, { consoleEvent: action.event });
4242
case ActionTypes.SHOW_MODAL:
43-
return Object.assign({}, state, { modalIsVisible: true, parentId: action.parentId });
43+
return Object.assign({}, state, {
44+
modalIsVisible: true,
45+
parentId: action.parentId,
46+
newFolderModalVisible: false
47+
});
4448
case ActionTypes.HIDE_MODAL:
4549
return Object.assign({}, state, { modalIsVisible: false });
4650
case ActionTypes.COLLAPSE_SIDEBAR:
@@ -62,7 +66,11 @@ const ide = (state = initialState, action) => {
6266
case ActionTypes.CLOSE_PROJECT_OPTIONS:
6367
return Object.assign({}, state, { projectOptionsVisible: false });
6468
case ActionTypes.SHOW_NEW_FOLDER_MODAL:
65-
return Object.assign({}, state, { newFolderModalVisible: true, parentId: action.parentId });
69+
return Object.assign({}, state, {
70+
newFolderModalVisible: true,
71+
parentId: action.parentId,
72+
modalIsVisible: false
73+
});
6674
case ActionTypes.CLOSE_NEW_FOLDER_MODAL:
6775
return Object.assign({}, state, { newFolderModalVisible: false });
6876
case ActionTypes.SHOW_SHARE_MODAL:

0 commit comments

Comments
 (0)