@@ -27,6 +27,8 @@ var AuthoredHints = require('./authoredHints');
2727var Instructions = require ( './templates/instructions/Instructions' ) ;
2828var DialogButtons = require ( './templates/DialogButtons' ) ;
2929var WireframeSendToPhone = require ( './templates/WireframeSendToPhone' ) ;
30+ import InstructionsDialogWrapper from './templates/instructions/InstructionsDialogWrapper' ;
31+ import DialogInstructions from './templates/instructions/DialogInstructions' ;
3032var assetsApi = require ( './clientApi' ) . assets ;
3133var assetPrefix = require ( './assetManagement/assetPrefix' ) ;
3234var annotationList = require ( './acemode/annotationList' ) ;
@@ -35,11 +37,16 @@ var shareWarnings = require('./shareWarnings');
3537import { setPageConstants } from './redux/pageConstants' ;
3638
3739var redux = require ( './redux' ) ;
40+ import { Provider } from 'react-redux' ;
3841import {
3942 substituteInstructionImages ,
4043 determineInstructionsConstants ,
4144 setInstructionsConstants
4245} from './redux/instructions' ;
46+ import {
47+ openDialog as openInstructionsDialog ,
48+ closeDialog as closeInstructionsDialog
49+ } from './redux/instructionsDialog' ;
4350import { setIsRunning } from './redux/runState' ;
4451var commonReducers = require ( './redux/commonReducers' ) ;
4552var combineReducers = require ( 'redux' ) . combineReducers ;
@@ -325,6 +332,17 @@ StudioApp.prototype.init = function (config) {
325332
326333 this . configureDom ( config ) ;
327334
335+ ReactDOM . render (
336+ < Provider store = { this . reduxStore } >
337+ < InstructionsDialogWrapper
338+ showInstructionsDialog = { ( autoClose , showHints ) => {
339+ this . showInstructionsDialog_ ( config . level , autoClose , showHints ) ;
340+ } }
341+ />
342+ </ Provider > ,
343+ document . body . appendChild ( document . createElement ( 'div' ) )
344+ ) ;
345+
328346 if ( config . usesAssets ) {
329347 assetPrefix . init ( config ) ;
330348
@@ -424,7 +442,7 @@ StudioApp.prototype.init = function (config) {
424442 return ;
425443 }
426444 var shouldAutoClose = ! ! config . level . aniGifURL ;
427- this . showInstructionsDialog_ ( config . level , shouldAutoClose , false ) ;
445+ this . reduxStore . dispatch ( openInstructionsDialog ( shouldAutoClose , false ) ) ;
428446 } . bind ( this ) ) ;
429447 }
430448
@@ -609,21 +627,6 @@ StudioApp.prototype.configureHints_ = function (config) {
609627 return ;
610628 }
611629
612- var bubble = document . getElementById ( 'bubble' ) ;
613- if ( bubble ) {
614- dom . addClickTouchEvent ( bubble , function ( ) {
615- const reduxState = this . reduxStore . getState ( ) ;
616- const instructionsInTopPane = reduxState . pageConstants . instructionsInTopPane ;
617- const hasAuthoredHints = reduxState . instructions . hasAuthoredHints ;
618-
619- // Don't show dialog on click in top pane unless we have hints
620- if ( instructionsInTopPane && ! hasAuthoredHints ) {
621- return ;
622- }
623- this . showInstructionsDialog_ ( config . level , false , true ) ;
624- } . bind ( this ) ) ;
625- }
626-
627630 var promptIcon = document . getElementById ( 'prompt-icon' ) ;
628631 this . authoredHintsController_ . display ( promptIcon ) ;
629632} ;
@@ -1077,44 +1080,8 @@ StudioApp.prototype.onReportComplete = function (response) {
10771080} ;
10781081
10791082/**
1080- * @param {string } [puzzleTitle] - Optional param that only gets used if we dont
1081- * have markdown instructions
1082- * @param {object } level
1083- * @param {boolean } showHints
1084- * @returns {React.element }
1085- */
1086- StudioApp . prototype . getInstructionsContent_ = function ( puzzleTitle , level , showHints ) {
1087- var renderedMarkdown ;
1088-
1089- var longInstructions = this . reduxStore . getState ( ) . instructions . longInstructions ;
1090-
1091- // longInstructions will be undefined if non-english
1092- if ( longInstructions ) {
1093- var markdownWithImages = substituteInstructionImages ( longInstructions ,
1094- this . skin . instructions2ImageSubstitutions ) ;
1095- renderedMarkdown = processMarkdown ( markdownWithImages ) ;
1096- }
1097-
1098- var authoredHints ;
1099- if ( showHints ) {
1100- authoredHints = this . authoredHintsController_ . getHintsDisplay ( ) ;
1101- }
1102-
1103- return (
1104- < Instructions
1105- puzzleTitle = { puzzleTitle }
1106- instructions = { substituteInstructionImages ( level . instructions ,
1107- this . skin . instructions2ImageSubstitutions ) }
1108- instructions2 = { substituteInstructionImages ( level . instructions2 ,
1109- this . skin . instructions2ImageSubstitutions ) }
1110- renderedMarkdown = { renderedMarkdown }
1111- markdownClassicMargins = { level . markdownInstructionsWithClassicMargins }
1112- aniGifURL = { level . aniGifURL }
1113- authoredHints = { authoredHints } />
1114- ) ;
1115- } ;
1116-
1117- /**
1083+ * Show our instructions dialog. This should never be called directly, and will
1084+ * instead be called when the state of our redux store changes.
11181085 * @param {object } level
11191086 * @param {boolean } autoClose - closes instructions after 32s if true
11201087 * @param {boolean } showHints
@@ -1145,9 +1112,6 @@ StudioApp.prototype.showInstructionsDialog_ = function (level, autoClose, showHi
11451112 }
11461113 }
11471114
1148- var instructionsContent = this . getInstructionsContent_ ( puzzleTitle , level ,
1149- showHints ) ;
1150-
11511115 // Create a div to eventually hold this content, and add it to the
11521116 // overall container. We don't want to render directly into the
11531117 // container just yet, because our React component could contain some
@@ -1188,6 +1152,9 @@ StudioApp.prototype.showInstructionsDialog_ = function (level, autoClose, showHi
11881152 var event = document . createEvent ( 'Event' ) ;
11891153 event . initEvent ( 'instructionsHidden' , true , true ) ;
11901154 document . dispatchEvent ( event ) ;
1155+
1156+ // update redux
1157+ this . reduxStore . dispatch ( closeInstructionsDialog ( ) ) ;
11911158 } , this ) ;
11921159
11931160 this . instructionsDialog = this . createModalDialog ( {
@@ -1201,10 +1168,17 @@ StudioApp.prototype.showInstructionsDialog_ = function (level, autoClose, showHi
12011168 header : headerElement
12021169 } ) ;
12031170
1171+ const authoredHints = showHints ?
1172+ this . authoredHintsController_ . getHintsDisplay ( ) : undefined ;
1173+
12041174 // Now that our elements are guaranteed to be in the DOM, we can
12051175 // render in our react components
1206- $ ( this . instructionsDialog . div ) . on ( 'show.bs.modal' , function ( ) {
1207- ReactDOM . render ( instructionsContent , instructionsReactContainer ) ;
1176+ $ ( this . instructionsDialog . div ) . on ( 'show.bs.modal' , ( ) => {
1177+ ReactDOM . render (
1178+ < Provider store = { this . reduxStore } >
1179+ < DialogInstructions authoredHints = { authoredHints } />
1180+ </ Provider > ,
1181+ instructionsReactContainer ) ;
12081182 } ) ;
12091183
12101184 if ( autoClose ) {
@@ -2762,6 +2736,7 @@ StudioApp.prototype.setPageConstants = function (config, appSpecificConstants) {
27622736 isShareView : ! ! config . share ,
27632737 pinWorkspaceToBottom : ! ! config . pinWorkspaceToBottom ,
27642738 instructionsInTopPane : ! ! config . showInstructionsInTopPane ,
2739+ hasContainedLevels : config . hasContainedLevels ,
27652740 puzzleNumber : level . puzzle_number ,
27662741 stageTotal : level . stage_total ,
27672742 noVisualization : false ,
0 commit comments