Skip to content

Fix needs saving mark 2 - for #576 #658

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 12 commits into from
Sep 7, 2018
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
5 changes: 0 additions & 5 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';
export const UPDATE_LINT_MESSAGE = 'UPDATE_LINT_MESSAGE';
export const CLEAR_LINT_MESSAGE = 'CLEAR_LINT_MESSAGE';

export const SHOW_FILE_OPTIONS = 'SHOW_FILE_OPTIONS';
export const HIDE_FILE_OPTIONS = 'HIDE_FILE_OPTIONS';

export const UPDATE_FILE_NAME = 'UPDATE_FILE_NAME';
export const DELETE_FILE = 'DELETE_FILE';
export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME';
export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME';

export const SET_AUTOSAVE = 'SET_AUTOSAVE';
export const SET_LINT_WARNING = 'SET_LINT_WARNING';
Expand Down
28 changes: 0 additions & 28 deletions client/modules/IDE/actions/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,34 +147,6 @@ export function createFolder(formProps) {
};
}

export function showFileOptions(fileId) {
return {
type: ActionTypes.SHOW_FILE_OPTIONS,
id: fileId
};
}

export function hideFileOptions(fileId) {
return {
type: ActionTypes.HIDE_FILE_OPTIONS,
id: fileId
};
}

export function showEditFileName(id) {
return {
type: ActionTypes.SHOW_EDIT_FILE_NAME,
id
};
}

export function hideEditFileName(id) {
return {
type: ActionTypes.HIDE_EDIT_FILE_NAME,
id
};
}

export function updateFileName(id, name) {
return {
type: ActionTypes.UPDATE_FILE_NAME,
Expand Down
46 changes: 29 additions & 17 deletions client/modules/IDE/components/FileNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export class FileNode extends React.Component {
this.validateFileName = this.validateFileName.bind(this);
this.handleFileClick = this.handleFileClick.bind(this);
this.toggleFileOptions = this.toggleFileOptions.bind(this);
this.hideFileOptions = this.hideFileOptions.bind(this);
this.showEditFileName = this.showEditFileName.bind(this);
this.hideEditFileName = this.hideEditFileName.bind(this);

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

handleFileClick(e) {
Expand All @@ -36,7 +44,7 @@ export class FileNode extends React.Component {

handleKeyPress(event) {
if (event.key === 'Enter') {
this.props.hideEditFileName(this.props.id);
this.hideEditFileName();
}
}

Expand All @@ -57,14 +65,26 @@ export class FileNode extends React.Component {

toggleFileOptions(e) {
e.preventDefault();
if (this.props.isOptionsOpen) {
this.props.hideFileOptions(this.props.id);
if (this.state.isOptionsOpen) {
this.setState({ isOptionsOpen: false });
} else {
this[`fileOptions-${this.props.id}`].focus();
this.props.showFileOptions(this.props.id);
this.setState({ isOptionsOpen: true });
}
}

hideFileOptions() {
this.setState({ isOptionsOpen: false });
}

showEditFileName() {
this.setState({ isEditingName: true });
}

hideEditFileName() {
this.setState({ isEditingName: false });
}

renderChild(childId) {
return (
<li key={childId}>
Expand All @@ -78,8 +98,8 @@ export class FileNode extends React.Component {
'sidebar__root-item': this.props.name === 'root',
'sidebar__file-item': this.props.name !== 'root',
'sidebar__file-item--selected': this.props.isSelectedFile,
'sidebar__file-item--open': this.props.isOptionsOpen,
'sidebar__file-item--editing': this.props.isEditingName,
'sidebar__file-item--open': this.state.isOptionsOpen,
'sidebar__file-item--editing': this.state.isEditingName,
'sidebar__file-item--closed': this.props.isFolderClosed
});
return (
Expand Down Expand Up @@ -123,7 +143,7 @@ export class FileNode extends React.Component {
ref={(element) => { this.fileNameInput = element; }}
onBlur={() => {
this.validateFileName();
this.props.hideEditFileName(this.props.id);
this.hideEditFileName();
}}
onKeyPress={this.handleKeyPress}
/>
Expand All @@ -133,7 +153,7 @@ export class FileNode extends React.Component {
ref={(element) => { this[`fileOptions-${this.props.id}`] = element; }}
tabIndex="0"
onClick={this.toggleFileOptions}
onBlur={() => setTimeout(() => this.props.hideFileOptions(this.props.id), 200)}
onBlur={() => setTimeout(this.hideFileOptions, 200)}
>
<InlineSVG src={downArrowUrl} />
</button>
Expand Down Expand Up @@ -173,7 +193,7 @@ export class FileNode extends React.Component {
<button
onClick={() => {
this.originalFileName = this.props.name;
this.props.showEditFileName(this.props.id);
this.showEditFileName();
setTimeout(() => this.fileNameInput.focus(), 0);
}}
className="sidebar__file-item-option"
Expand Down Expand Up @@ -222,15 +242,9 @@ FileNode.propTypes = {
name: PropTypes.string.isRequired,
fileType: PropTypes.string.isRequired,
isSelectedFile: PropTypes.bool,
isOptionsOpen: PropTypes.bool,
isEditingName: PropTypes.bool,
isFolderClosed: PropTypes.bool,
setSelectedFile: PropTypes.func.isRequired,
showFileOptions: PropTypes.func.isRequired,
hideFileOptions: PropTypes.func.isRequired,
deleteFile: PropTypes.func.isRequired,
showEditFileName: PropTypes.func.isRequired,
hideEditFileName: PropTypes.func.isRequired,
updateFileName: PropTypes.func.isRequired,
resetSelectedFile: PropTypes.func.isRequired,
newFile: PropTypes.func.isRequired,
Expand All @@ -242,8 +256,6 @@ FileNode.propTypes = {
FileNode.defaultProps = {
parentId: '0',
isSelectedFile: false,
isOptionsOpen: false,
isEditingName: false,
isFolderClosed: false
};

Expand Down
8 changes: 0 additions & 8 deletions client/modules/IDE/pages/IDEView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,7 @@ class IDEView extends React.Component {
setSelectedFile={this.props.setSelectedFile}
newFile={this.props.newFile}
isExpanded={this.props.ide.sidebarIsExpanded}
showFileOptions={this.props.showFileOptions}
hideFileOptions={this.props.hideFileOptions}
deleteFile={this.props.deleteFile}
showEditFileName={this.props.showEditFileName}
hideEditFileName={this.props.hideEditFileName}
updateFileName={this.props.updateFileName}
projectOptionsVisible={this.props.ide.projectOptionsVisible}
openProjectOptions={this.props.openProjectOptions}
Expand Down Expand Up @@ -622,11 +618,7 @@ IDEView.propTypes = {
cloneProject: PropTypes.func.isRequired,
expandConsole: PropTypes.func.isRequired,
collapseConsole: PropTypes.func.isRequired,
showFileOptions: PropTypes.func.isRequired,
hideFileOptions: PropTypes.func.isRequired,
deleteFile: PropTypes.func.isRequired,
showEditFileName: PropTypes.func.isRequired,
hideEditFileName: PropTypes.func.isRequired,
updateFileName: PropTypes.func.isRequired,
showEditProjectName: PropTypes.func.isRequired,
hideEditProjectName: PropTypes.func.isRequired,
Expand Down
32 changes: 0 additions & 32 deletions client/modules/IDE/reducers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,6 @@ const files = (state, action) => {
fileType: action.fileType || 'file'
}];
}
case ActionTypes.SHOW_FILE_OPTIONS:
return state.map((file) => {
if (file.id !== action.id) {
return file;
}

return Object.assign({}, file, { isOptionsOpen: true });
});
case ActionTypes.HIDE_FILE_OPTIONS:
return state.map((file) => {
if (file.id !== action.id) {
return file;
}

return Object.assign({}, file, { isOptionsOpen: false });
});
case ActionTypes.UPDATE_FILE_NAME:
return state.map((file) => {
if (file.id !== action.id) {
Expand All @@ -192,22 +176,6 @@ const files = (state, action) => {
// });
// return newState.filter(file => file.id !== action.id);
}
case ActionTypes.SHOW_EDIT_FILE_NAME:
return state.map((file) => {
if (file.id !== action.id) {
return file;
}

return Object.assign({}, file, { isEditingName: true });
});
case ActionTypes.HIDE_EDIT_FILE_NAME:
return state.map((file) => {
if (file.id !== action.id) {
return file;
}

return Object.assign({}, file, { isEditingName: false });
});
case ActionTypes.SET_SELECTED_FILE:
return state.map((file) => {
if (file.id === action.selectedFile) {
Expand Down