From 8b6a6cb4b4f0beecf3070e5fdbec81265a7d7566 Mon Sep 17 00:00:00 2001 From: Ben Wheeler <wheeler.benjamin@gmail.com> Date: Thu, 15 Nov 2018 00:28:39 -0500 Subject: [PATCH] project-watcher can request eventual callback, or immediately call callback --- src/components/menu-bar/menu-bar.jsx | 25 +++++++++++++++++-------- src/containers/project-watcher.jsx | 22 ++++++++++++++-------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/components/menu-bar/menu-bar.jsx b/src/components/menu-bar/menu-bar.jsx index 12fe0c273..35939d377 100644 --- a/src/components/menu-bar/menu-bar.jsx +++ b/src/components/menu-bar/menu-bar.jsx @@ -27,6 +27,7 @@ import TurboMode from '../../containers/turbo-mode.jsx'; import {openTipsLibrary} from '../../reducers/modals'; import {setPlayer} from '../../reducers/mode'; import { + autoUpdateProject, getIsUpdating, getIsShowingProject, manualUpdateProject, @@ -172,17 +173,23 @@ class MenuBar extends React.Component { } handleClickSeeCommunity (requestSeeCommunity) { if (this.props.canSave) { // save before transitioning to project page - this.props.onClickSave(); + this.props.autoSave(); + requestSeeCommunity(true); // queue the transition to project page + } else { + requestSeeCommunity(false); // immediately transition to project page } - requestSeeCommunity(); // queue the transition to project page } handleClickShare (requestSeeCommunity) { - if (this.props.canSave && !this.props.isShared) { // save before transitioning to project page - this.props.onClickSave(); - } - if (this.props.canShare && !this.props.isShared) { // save before transitioning to project page - this.props.onShare(); - requestSeeCommunity(); // queue the transition to project page + if (!this.props.isShared) { + if (this.props.canShare) { // save before transitioning to project page + this.props.onShare(); + } + if (this.props.canSave) { // save before transitioning to project page + this.props.autoSave(); + requestSeeCommunity(true); // queue the transition to project page + } else { + requestSeeCommunity(false); // immediately transition to project page + } } } handleRestoreOption (restoreFun) { @@ -681,6 +688,7 @@ MenuBar.propTypes = { authorId: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), authorThumbnailUrl: PropTypes.string, authorUsername: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), + autoUpdateProject: PropTypes.func, canCreateCopy: PropTypes.bool, canCreateNew: PropTypes.bool, canEditTitle: PropTypes.bool, @@ -749,6 +757,7 @@ const mapStateToProps = state => { }; const mapDispatchToProps = dispatch => ({ + autoSave: () => dispatch(autoUpdateProject()), onOpenTipLibrary: () => dispatch(openTipsLibrary()), onClickAccount: () => dispatch(openAccountMenu()), onRequestCloseAccount: () => dispatch(closeAccountMenu()), diff --git a/src/containers/project-watcher.jsx b/src/containers/project-watcher.jsx index 8a75f8e2b..dbcddd1cf 100644 --- a/src/containers/project-watcher.jsx +++ b/src/containers/project-watcher.jsx @@ -20,18 +20,24 @@ class ProjectWatcher extends React.Component { } componentDidUpdate (prevProps) { if (this.state.requesting && this.props.isShowingWithId && !prevProps.isShowingWithId) { - this.props.onShowingWithId(); - this.setState({ // eslint-disable-line react/no-did-update-set-state - requesting: false - }); + this.fulfillRequest(); } - } - setRequesting () { - this.setState({ - requesting: true + fulfillRequest () { + this.props.onShowingWithId(); + this.setState({ // eslint-disable-line react/no-did-update-set-state + requesting: false }); } + setRequesting (waitForRequest) { + if (waitForRequest) { + this.setState({ + requesting: true + }); + } else { // fulfill immediately + this.fulfillRequest(); + } + } render () { return this.props.children( this.setRequesting -- GitLab