Skip to content
Snippets Groups Projects
Unverified Commit 75a84747 authored by Ray Schamp's avatar Ray Schamp Committed by GitHub
Browse files

Merge pull request #3175 from LLK/smoke

Merge Smoke to Develop
parents 27f5d258 5aa2f617
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import {setPlayer, setFullScreen} from '../reducers/mode.js'; ...@@ -10,6 +10,7 @@ import {setPlayer, setFullScreen} from '../reducers/mode.js';
import locales from 'scratch-l10n'; import locales from 'scratch-l10n';
import {detectLocale} from './detect-locale'; import {detectLocale} from './detect-locale';
import {detectTutorialId} from './tutorial-from-url';
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
...@@ -50,16 +51,27 @@ const AppStateHOC = function (WrappedComponent, localesOnly) { ...@@ -50,16 +51,27 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
guiInitialState, guiInitialState,
guiMiddleware, guiMiddleware,
initFullScreen, initFullScreen,
initPlayer initPlayer,
initTutorialCard
} = guiRedux; } = guiRedux;
const {ScratchPaintReducer} = require('scratch-paint'); const {ScratchPaintReducer} = require('scratch-paint');
let initializedGui = guiInitialState; let initializedGui = guiInitialState;
if (props.isFullScreen) { if (props.isFullScreen || props.isPlayerOnly) {
initializedGui = initFullScreen(initializedGui); if (props.isFullScreen) {
} initializedGui = initFullScreen(initializedGui);
if (props.isPlayerOnly) { }
initializedGui = initPlayer(initializedGui); if (props.isPlayerOnly) {
initializedGui = initPlayer(initializedGui);
}
} else {
const tutorialId = detectTutorialId();
if (tutorialId !== null) {
// When loading a tutorial from the URL,
// load w/o preview modal
// open requested tutorial card
initializedGui = initTutorialCard(initializedGui, tutorialId);
}
} }
reducers = { reducers = {
locales: localesReducer, locales: localesReducer,
......
...@@ -99,7 +99,8 @@ export default { ...@@ -99,7 +99,8 @@ export default {
'add-sprite' 'add-sprite'
] ]
} }
] ],
urlId: 1
}, },
'animate-a-name': { 'animate-a-name': {
name: ( name: (
...@@ -172,7 +173,8 @@ export default { ...@@ -172,7 +173,8 @@ export default {
'glide-around' 'glide-around'
] ]
} }
] ],
urlId: 2
}, },
'Make-Music': { 'Make-Music': {
name: ( name: (
...@@ -239,7 +241,8 @@ export default { ...@@ -239,7 +241,8 @@ export default {
'add-sprite' 'add-sprite'
] ]
} }
] ],
urlId: 3
}, },
'Make-A-Game': { 'Make-A-Game': {
name: ( name: (
...@@ -323,7 +326,8 @@ export default { ...@@ -323,7 +326,8 @@ export default {
'move-around-with-arrow-keys' 'move-around-with-arrow-keys'
] ]
} }
] ],
urlId: 4
}, },
'Chase-Game': { 'Chase-Game': {
...@@ -425,7 +429,8 @@ export default { ...@@ -425,7 +429,8 @@ export default {
'move-around-with-arrow-keys' 'move-around-with-arrow-keys'
] ]
} }
] ],
urlId: 5
}, },
'add-sprite': { 'add-sprite': {
name: ( name: (
...@@ -453,7 +458,8 @@ export default { ...@@ -453,7 +458,8 @@ export default {
'switch-costume' 'switch-costume'
] ]
} }
] ],
urlId: 6
}, },
'add-a-backdrop': { 'add-a-backdrop': {
name: ( name: (
...@@ -471,7 +477,8 @@ export default { ...@@ -471,7 +477,8 @@ export default {
'change-size', 'change-size',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 7
}, },
'change-size': { 'change-size': {
name: ( name: (
...@@ -489,7 +496,8 @@ export default { ...@@ -489,7 +496,8 @@ export default {
'glide-around', 'glide-around',
'spin-video' 'spin-video'
] ]
}] }],
urlId: 8
}, },
'glide-around': { 'glide-around': {
name: ( name: (
...@@ -507,7 +515,8 @@ export default { ...@@ -507,7 +515,8 @@ export default {
'add-a-backdrop', 'add-a-backdrop',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 9
}, },
'record-a-sound': { 'record-a-sound': {
...@@ -526,8 +535,8 @@ export default { ...@@ -526,8 +535,8 @@ export default {
'Make-Music', 'Make-Music',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 10
}, },
'spin-video': { 'spin-video': {
name: ( name: (
...@@ -545,7 +554,8 @@ export default { ...@@ -545,7 +554,8 @@ export default {
'add-a-backdrop', 'add-a-backdrop',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 11
}, },
'hide-and-show': { 'hide-and-show': {
name: ( name: (
...@@ -563,7 +573,8 @@ export default { ...@@ -563,7 +573,8 @@ export default {
'add-a-backdrop', 'add-a-backdrop',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 12
}, },
'switch-costume': { 'switch-costume': {
...@@ -582,7 +593,8 @@ export default { ...@@ -582,7 +593,8 @@ export default {
'add-a-backdrop', 'add-a-backdrop',
'add-effects' 'add-effects'
] ]
}] }],
urlId: 13
}, },
'move-around-with-arrow-keys': { 'move-around-with-arrow-keys': {
...@@ -601,7 +613,8 @@ export default { ...@@ -601,7 +613,8 @@ export default {
'add-a-backdrop', 'add-a-backdrop',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 14
}, },
'add-effects': { 'add-effects': {
name: ( name: (
...@@ -619,6 +632,7 @@ export default { ...@@ -619,6 +632,7 @@ export default {
'add-a-backdrop', 'add-a-backdrop',
'switch-costume' 'switch-costume'
] ]
}] }],
urlId: 15
} }
}; };
/**
* @fileoverview
* Utility function to detect tutorial id from query paramenter on the URL.
*/
import tutorials from './libraries/decks/index.jsx';
import analytics from './analytics';
/**
* Get the tutorial id from the given numerical id (representing the
* url id of the tutorial).
* @param {number} urlId The URL Id for the tutorial
* @returns {string} The string id for the tutorial, or null if the URL ID
* was not found.
*/
const getDeckIdFromUrlId = urlId => {
for (const deckId in tutorials) {
if (tutorials[deckId].urlId === urlId) {
analytics.event({
category: 'how-to',
action: 'load from url',
label: `${deckId}`
});
return deckId;
}
}
return null;
};
/**
* Check if there's a tutorial id provided as a query parameter in the URL.
* Return the corresponding tutorial id or null if not found.
* @return {string} The ID of the requested tutorial or null if no tutorial was
* requested or found.
*/
const detectTutorialId = () => {
if (window.location.search.indexOf('tutorial=') !== -1) {
const urlTutorialId = window.location.search.match(/(?:tutorial)=(\d+)/)[1];
if (urlTutorialId) {
return getDeckIdFromUrlId(Number(urlTutorialId));
}
}
return null;
};
export {
detectTutorialId
};
...@@ -21,6 +21,8 @@ import vmReducer, {vmInitialState} from './vm'; ...@@ -21,6 +21,8 @@ import vmReducer, {vmInitialState} from './vm';
import vmStatusReducer, {vmStatusInitialState} from './vm-status'; import vmStatusReducer, {vmStatusInitialState} from './vm-status';
import throttle from 'redux-throttle'; import throttle from 'redux-throttle';
import decks from '../lib/libraries/decks/index.jsx';
const guiMiddleware = compose(applyMiddleware(throttle(300, {leading: true, trailing: true}))); const guiMiddleware = compose(applyMiddleware(throttle(300, {leading: true, trailing: true})));
const guiInitialState = { const guiInitialState = {
...@@ -67,6 +69,27 @@ const initFullScreen = function (currentState) { ...@@ -67,6 +69,27 @@ const initFullScreen = function (currentState) {
); );
}; };
const initTutorialCard = function (currentState, deckId) {
return Object.assign(
{},
currentState,
{
modals: {
previewInfo: false
},
cards: {
visible: true,
content: decks,
activeDeckId: deckId,
step: 0,
x: 0,
y: 0,
dragging: false
}
}
);
};
const guiReducer = combineReducers({ const guiReducer = combineReducers({
assetDrag: assetDragReducer, assetDrag: assetDragReducer,
blockDrag: blockDragReducer, blockDrag: blockDragReducer,
...@@ -95,5 +118,6 @@ export { ...@@ -95,5 +118,6 @@ export {
guiInitialState, guiInitialState,
guiMiddleware, guiMiddleware,
initFullScreen, initFullScreen,
initPlayer initPlayer,
initTutorialCard
}; };
...@@ -72,7 +72,7 @@ describe('Loading scratch gui', () => { ...@@ -72,7 +72,7 @@ describe('Loading scratch gui', () => {
const projectId = '96708228'; const projectId = '96708228';
await loadUri(`${uri}#${projectId}`); await loadUri(`${uri}#${projectId}`);
await clickXpath('//button[@title="Try It"]'); await clickXpath('//button[@title="Try It"]');
await new Promise(resolve => setTimeout(resolve, 2000)); await new Promise(resolve => setTimeout(resolve, 3000));
await clickXpath('//img[@title="Go"]'); await clickXpath('//img[@title="Go"]');
await new Promise(resolve => setTimeout(resolve, 2000)); await new Promise(resolve => setTimeout(resolve, 2000));
await clickXpath('//img[@title="Stop"]'); await clickXpath('//img[@title="Stop"]');
......
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