Disconnect from cloud when viewing someone else's project in editor mode

This commit is contained in:
Karishma Chadha committed 2018-11-27 17:54:50 -05:00
1 parent 7c7ec110d0
commit e752ffdf8a
3 files changed
+22 -8

No files matched your search

+12 -4
View File
@@ -46,18 +46,22 @@ const cloudManagerHOC = function (WrappedComponent) {
// This should cover info about the website specifically, like scrather status
return !!(props.cloudHost && props.username && props.vm && props.projectId);
}
shouldNotModifyCloudData (props) {
return (props.hasEverEnteredEditor && !props.canSave);
}
shouldConnect (props) {
return !this.isConnected() && this.canUseCloud(props) && props.isShowingWithId;
return !this.isConnected() && this.canUseCloud(props) &&
props.isShowingWithId && !this.shouldNotModifyCloudData(props);
}
shouldDisconnect (props, prevProps) {
return this.isConnected() &&
( // Can no longer use cloud or cloud provider info is now stale
!this.canUseCloud(this.props) ||
(props.projectId !== prevProps.projectId) ||
(props.username !== prevProps.username)
(props.username !== prevProps.username) ||
// Editing someone else's project
this.shouldNotModifyCloudData(props)
);
// TODO need to add provisions for viewing someone
// else's project in editor mode
}
isConnected () {
return this.cloudProvider && !!this.cloudProvider.connection;
@@ -83,6 +87,7 @@ const cloudManagerHOC = function (WrappedComponent) {
cloudHost,
projectId,
username,
hasEverEnteredEditor,
isShowingWithId,
/* eslint-enable no-unused-vars */
vm,
@@ -99,7 +104,9 @@ const cloudManagerHOC = function (WrappedComponent) {
}
CloudManager.propTypes = {
canSave: PropTypes.bool.isRequired,
cloudHost: PropTypes.string,
hasEverEnteredEditor: PropTypes.bool,
isShowingWithId: PropTypes.bool,
projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
username: PropTypes.string,
@@ -109,6 +116,7 @@ const cloudManagerHOC = function (WrappedComponent) {
const mapStateToProps = state => {
const loadingState = state.scratchGui.projectState.loadingState;
return {
hasEverEnteredEditor: state.scratchGui.mode.hasEverEnteredEditor,
isShowingWithId: getIsShowingWithId(loadingState),
projectId: state.scratchGui.projectState.projectId
};
+6 -2
View File
@@ -60,7 +60,10 @@ const initPlayer = function (currentState) {
currentState,
{mode: {
isFullScreen: currentState.mode.isFullScreen,
isPlayerOnly: true
isPlayerOnly: true,
// When initializing in player mode, make sure to reset
// hasEverEnteredEditorMode
hasEverEnteredEditor: false
}}
);
};
@@ -70,7 +73,8 @@ const initFullScreen = function (currentState) {
currentState,
{mode: {
isFullScreen: true,
isPlayerOnly: currentState.mode.isPlayerOnly
isPlayerOnly: currentState.mode.isPlayerOnly,
hasEverEnteredEditor: currentState.mode.hasEverEnteredEditor
}}
);
};
+4 -2
View File
@@ -3,7 +3,8 @@ const SET_PLAYER = 'scratch-gui/mode/SET_PLAYER';
const initialState = {
isFullScreen: false,
isPlayerOnly: false
isPlayerOnly: false,
hasEverEnteredEditor: true
};
const reducer = function (state, action) {
@@ -17,7 +18,8 @@ const reducer = function (state, action) {
case SET_PLAYER:
return {
isFullScreen: state.isFullScreen,
isPlayerOnly: action.isPlayerOnly
isPlayerOnly: action.isPlayerOnly,
hasEverEnteredEditor: state.hasEverEnteredEditor || !action.isPlayerOnly
};
default:
return state;