From 52291c69f2ced17def094f4e69a6517a14fa1bd7 Mon Sep 17 00:00:00 2001 From: Nikhil Sharma <30630904+nik72619c@users.noreply.github.com> Date: Sun, 17 Mar 2019 14:49:45 +0530 Subject: [PATCH 1/4] fixed non-optimal function declarations --- client/components/Nav.jsx | 194 ++++++++++++++++++++++++-------------- 1 file changed, 121 insertions(+), 73 deletions(-) diff --git a/client/components/Nav.jsx b/client/components/Nav.jsx index 8660f2bc..0fe1dcad 100644 --- a/client/components/Nav.jsx +++ b/client/components/Nav.jsx @@ -28,6 +28,22 @@ class Nav extends React.PureComponent { this.clearHideTimeout = this.clearHideTimeout.bind(this); this.handleClick = this.handleClick.bind(this); this.handleClickOutside = this.handleClickOutside.bind(this); + this.handleSave = this.handleSave.bind(this); + this.handleNew = this.handleNew.bind(this); + this.handleDuplicate = this.handleDuplicate.bind(this); + this.handleShare = this.handleShare.bind(this); + this.handleDownload = this.handleDownload.bind(this); + this.handleFind = this.handleFind.bind(this); + this.handleAddFile = this.handleAddFile.bind(this); + this.handleAddFolder = this.handleAddFolder.bind(this); + this.handleFindNext = this.handleFindNext.bind(this); + this.handleRun = this.handleRun.bind(this); + this.handleFindPrevious = this.handleFindPrevious.bind(this); + this.handleStop = this.handleStop.bind(this); + this.handleStartAccessible = this.handleStartAccessible.apply(this); + this.handleStopAccessible = this.handleStopAccessible.bind(this); + this.handleKeyboardShortcuts = this.handleKeyboardShortcuts.bind(this); + this.handleLogout = this.handleLogout.bind(this); } componentWillMount() { @@ -52,6 +68,95 @@ class Nav extends React.PureComponent { this.handleClickOutside(); } + handleNew() { + if (!this.props.unsavedChanges) { + this.props.newProject(); + } else if (this.props.warnIfUnsavedChanges()) { + this.props.newProject(); + } + this.setDropdown('none'); + } + + handleSave() { + if (this.props.user.authenticated) { + this.props.saveProject(this.props.cmController.getContent()); + } else { + this.props.showErrorModal('forceAuthentication'); + } + this.setDropdown('none'); + } + + handleFind() { + this.props.cmController.showFind(); + this.setDropdown('none'); + } + + handleFindNext() { + this.props.cmController.findNext(); + this.setDropdown('none'); + } + + handleFindPrevious() { + this.props.cmController.findPrev(); + this.setDropdown('none'); + } + + handleAddFile() { + this.props.newFile(); + this.setDropdown('none'); + } + + handleAddFolder() { + this.props.newFolder(); + this.setDropdown('none'); + } + + handleRun() { + this.props.startSketch(); + this.setDropdown('none'); + } + + handleStop() { + this.props.stopSketch(); + this.setDropdown('none'); + } + + handleStartAccessible() { + this.props.setAllAccessibleOutput(true); + this.setDropdown('none'); + } + + handleStopAccessible() { + this.props.setAllAccessibleOutput(false); + this.setDropdown('none'); + } + + handleKeyboardShortcuts() { + this.props.showKeyboardShortcutModal(); + this.setDropdown('none'); + } + + handleLogout() { + this.props.logoutUser(); + this.setDropdown('none'); + } + + handleDownload() { + this.props.autosaveProject(); + this.props.exportProjectAsZip(this.props.project.id); + this.setDropdown('none'); + } + + handleDuplicate() { + this.props.cloneProject(); + this.setDropdown('none'); + } + + handleShare() { + this.props.showShareModal(); + this.setDropdown('none'); + } + handleClickOutside() { this.setState({ dropdownOpen: 'none' @@ -138,14 +243,7 @@ class Nav extends React.PureComponent {
  • @@ -529,10 +580,7 @@ class Nav extends React.PureComponent {