Skip to content
Snippets Groups Projects
Unverified Commit 468da6fc authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #5059 from paulkaplan/fix-save-after-recording

Fix saving after recording a sound
parents 043cbec9 b07c6451
No related branches found
Tags 0.1.0-prerelease.20190806192519
No related merge requests found
...@@ -60,9 +60,9 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -60,9 +60,9 @@ const vmListenerHOC = function (WrappedComponent) {
this.props.vm.postIOData('userData', {username: this.props.username}); this.props.vm.postIOData('userData', {username: this.props.username});
} }
// Re-request a targets update when the shouldEmitUpdate state changes to true // Re-request a targets update when the shouldUpdateTargets state changes to true
// i.e. when the editor transitions out of fullscreen/player only modes // i.e. when the editor transitions out of fullscreen/player only modes
if (this.props.shouldEmitUpdates && !prevProps.shouldEmitUpdates) { if (this.props.shouldUpdateTargets && !prevProps.shouldUpdateTargets) {
this.props.vm.emitTargetsUpdate(false /* Emit the event, but do not trigger project change */); this.props.vm.emitTargetsUpdate(false /* Emit the event, but do not trigger project change */);
} }
} }
...@@ -74,12 +74,12 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -74,12 +74,12 @@ const vmListenerHOC = function (WrappedComponent) {
} }
} }
handleProjectChanged () { handleProjectChanged () {
if (this.props.shouldEmitUpdates && !this.props.projectChanged) { if (this.props.shouldUpdateProjectChanged && !this.props.projectChanged) {
this.props.onProjectChanged(); this.props.onProjectChanged();
} }
} }
handleTargetsUpdate (data) { handleTargetsUpdate (data) {
if (this.props.shouldEmitUpdates) { if (this.props.shouldUpdateTargets) {
this.props.onTargetsUpdate(data); this.props.onTargetsUpdate(data);
} }
} }
...@@ -118,7 +118,8 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -118,7 +118,8 @@ const vmListenerHOC = function (WrappedComponent) {
/* eslint-disable no-unused-vars */ /* eslint-disable no-unused-vars */
attachKeyboardEvents, attachKeyboardEvents,
projectChanged, projectChanged,
shouldEmitUpdates, shouldUpdateTargets,
shouldUpdateProjectChanged,
onBlockDragUpdate, onBlockDragUpdate,
onGreenFlag, onGreenFlag,
onKeyDown, onKeyDown,
...@@ -158,7 +159,8 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -158,7 +159,8 @@ const vmListenerHOC = function (WrappedComponent) {
onTurboModeOff: PropTypes.func.isRequired, onTurboModeOff: PropTypes.func.isRequired,
onTurboModeOn: PropTypes.func.isRequired, onTurboModeOn: PropTypes.func.isRequired,
projectChanged: PropTypes.bool, projectChanged: PropTypes.bool,
shouldEmitUpdates: PropTypes.bool, shouldUpdateTargets: PropTypes.bool,
shouldUpdateProjectChanged: PropTypes.bool,
username: PropTypes.string, username: PropTypes.string,
vm: PropTypes.instanceOf(VM).isRequired vm: PropTypes.instanceOf(VM).isRequired
}; };
...@@ -170,8 +172,10 @@ const vmListenerHOC = function (WrappedComponent) { ...@@ -170,8 +172,10 @@ const vmListenerHOC = function (WrappedComponent) {
projectChanged: state.scratchGui.projectChanged, projectChanged: state.scratchGui.projectChanged,
// Do not emit target or project updates in fullscreen or player only mode // Do not emit target or project updates in fullscreen or player only mode
// or when recording sounds (it leads to garbled recordings on low-power machines) // or when recording sounds (it leads to garbled recordings on low-power machines)
shouldEmitUpdates: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly && shouldUpdateTargets: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly &&
!state.scratchGui.modals.soundRecorder, !state.scratchGui.modals.soundRecorder,
// Do not update the projectChanged state in fullscreen or player only mode
shouldUpdateProjectChanged: !state.scratchGui.mode.isFullScreen && !state.scratchGui.mode.isPlayerOnly,
vm: state.scratchGui.vm, vm: state.scratchGui.vm,
username: state.session && state.session.session && state.session.session.user ? username: state.session && state.session.session && state.session.session.user ?
state.session.session.user.username : '' state.session.session.user.username : ''
......
...@@ -91,4 +91,46 @@ describe('VMListenerHOC', () => { ...@@ -91,4 +91,46 @@ describe('VMListenerHOC', () => {
const actions = store.getActions(); const actions = store.getActions();
expect(actions.length).toEqual(0); expect(actions.length).toEqual(0);
}); });
test('PROJECT_CHANGED does dispatch if the sound recorder is visible', () => {
const Component = () => (<div />);
const WrappedComponent = vmListenerHOC(Component);
store = mockStore({
scratchGui: {
mode: {},
modals: {soundRecorder: true},
vm: vm
}
});
mount(
<WrappedComponent
store={store}
vm={vm}
/>
);
vm.emit('PROJECT_CHANGED');
const actions = store.getActions();
expect(actions.length).toEqual(1);
});
test('PROJECT_CHANGED does not dispatch if in fullscreen mode', () => {
const Component = () => (<div />);
const WrappedComponent = vmListenerHOC(Component);
store = mockStore({
scratchGui: {
mode: {isFullScreen: true},
modals: {soundRecorder: true},
vm: vm
}
});
mount(
<WrappedComponent
store={store}
vm={vm}
/>
);
vm.emit('PROJECT_CHANGED');
const actions = store.getActions();
expect(actions.length).toEqual(0);
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment