@@ -1130,21 +1130,27 @@ module ControlPanel = {
11301130 ~state : CompilerManagerHook .state ,
11311131 ~dispatch : CompilerManagerHook .action => unit ,
11321132 ~editorCode : React .ref <string >,
1133- ~runOutput ,
1134- ~toggleRunOutput ,
11351133 ) => {
11361134 let children = switch state {
11371135 | Init => React .string ("Initializing..." )
11381136 | SwitchingCompiler (_ready , _version ) => React .string ("Switching Compiler..." )
1139- | Compiling (_ , _ )
1137+ | Compiling (_ )
1138+ | Executing (_ )
11401139 | Ready (_ ) =>
11411140 let onFormatClick = evt => {
11421141 ReactEvent .Mouse .preventDefault (evt )
11431142 dispatch (Format (editorCode .current ))
11441143 }
11451144
1145+ let autoRun = switch state {
1146+ | CompilerManagerHook .Executing ({state : {autoRun : true }})
1147+ | Compiling ({autoRun : true })
1148+ | Ready ({autoRun : true }) => true
1149+ | _ => false
1150+ }
1151+
11461152 <div className = "flex flex-row gap-x-2" >
1147- <ToggleButton checked = runOutput onChange = {_ => toggleRunOutput ( )}>
1153+ <ToggleButton checked = autoRun onChange = {_ => dispatch ( ToggleAutoRun )}>
11481154 {React .string ("Auto-run" )}
11491155 </ToggleButton >
11501156 <Button onClick = onFormatClick > {React .string ("Format" )} </Button >
@@ -1176,7 +1182,6 @@ module OutputPanel = {
11761182 ~compilerState : CompilerManagerHook .state ,
11771183 ~editorCode : React .ref <string >,
11781184 ~currentTab : tab ,
1179- ~runOutput ,
11801185 ) => {
11811186 /*
11821187 We need the prevState to understand different
@@ -1199,8 +1204,9 @@ module OutputPanel = {
11991204 }
12001205 | (_ , Ready ({result : Comp (Success (_ )) as result })) =>
12011206 ControlPanel .codeFromResult (result )-> Some
1202- | (Ready ({result : Comp (Success (_ )) as result }), Compiling (_ , _ )) =>
1207+ | (Ready ({result : Comp (Success (_ )) as result }), Compiling (_ )) =>
12031208 ControlPanel .codeFromResult (result )-> Some
1209+ | (_ , Executing ({jsCode })) => Some (jsCode )
12041210 | _ => None
12051211 }
12061212 | None =>
@@ -1213,8 +1219,9 @@ module OutputPanel = {
12131219 prevState .current = Some (compilerState )
12141220
12151221 let resultPane = switch compilerState {
1216- | Compiling (ready , _ )
1217- | Ready (ready ) =>
1222+ | Compiling (ready )
1223+ | Ready (ready )
1224+ | Executing ({state : ready }) =>
12181225 switch ready .result {
12191226 | Comp (Success (_ ))
12201227 | Conv (Success (_ )) => React .null
@@ -1246,8 +1253,9 @@ module OutputPanel = {
12461253 </div >
12471254
12481255 let errorPane = switch compilerState {
1249- | Compiling (ready , _ )
1256+ | Compiling (ready )
12501257 | Ready (ready )
1258+ | Executing ({state : ready })
12511259 | SwitchingCompiler (ready , _ ) =>
12521260 <ResultPane
12531261 targetLang = ready .targetLang
@@ -1260,7 +1268,8 @@ module OutputPanel = {
12601268
12611269 let settingsPane = switch compilerState {
12621270 | Ready (ready )
1263- | Compiling (ready , _ )
1271+ | Compiling (ready )
1272+ | Executing ({state : ready })
12641273 | SwitchingCompiler (ready , _ ) =>
12651274 let config = ready .selected .config
12661275 let setConfig = config => compilerDispatch (UpdateConfig (config ))
@@ -1273,7 +1282,9 @@ module OutputPanel = {
12731282 let prevSelected = React .useRef (0 )
12741283
12751284 let selected = switch compilerState {
1276- | Compiling (_ , _ ) => prevSelected .current
1285+ | Executing (_ )
1286+ | Compiling (_ ) =>
1287+ prevSelected .current
12771288 | Ready (ready ) =>
12781289 switch ready .result {
12791290 | Comp (Success (_ ))
@@ -1285,10 +1296,10 @@ module OutputPanel = {
12851296
12861297 prevSelected .current = selected
12871298
1288- let ( logs , setLogs ) = React . useState ( _ => [] )
1299+ let appendLog = ( level , content ) => compilerDispatch ( AppendLog ({ level , content }) )
12891300
12901301 let tabs = [
1291- (Output , <OutputPanel runOutput compilerState logs setLogs />),
1302+ (Output , <OutputPanel compilerState appendLog />),
12921303 (JavaScript , output ),
12931304 (Problems , errorPane ),
12941305 (Settings , settingsPane ),
@@ -1483,7 +1494,7 @@ let make = (~versions: array<string>) => {
14831494 }
14841495
14851496 None
1486- }, [ compilerState ] )
1497+ }, ( compilerState , compilerDispatch ) )
14871498
14881499 let (layout , setLayout ) = React .useState (_ =>
14891500 Webapi .Window .innerWidth < breakingPoint ? Column : Row
@@ -1693,17 +1704,12 @@ let make = (~versions: array<string>) => {
16931704 </button >
16941705 })
16951706
1696- let (runOutput , setRunOutput ) = React .useState (() => false )
1697- let toggleRunOutput = () => setRunOutput (prev => ! prev )
1698-
16991707 <main className = {"flex flex-col bg-gray-100 overflow-hidden" }>
17001708 <ControlPanel
17011709 actionIndicatorKey = {Int .toString (actionCount )}
17021710 state = compilerState
17031711 dispatch = compilerDispatch
17041712 editorCode
1705- runOutput
1706- toggleRunOutput
17071713 />
17081714 <div
17091715 className = {` flex ${layout == Column ? "flex-col" : "flex-row" }` }
@@ -1758,7 +1764,7 @@ let make = (~versions: array<string>) => {
17581764 {React .array (headers )}
17591765 </div >
17601766 <div ref = {ReactDOM .Ref .domRef (subPanelRef )} className = "overflow-auto" >
1761- <OutputPanel currentTab compilerDispatch compilerState editorCode runOutput />
1767+ <OutputPanel currentTab compilerDispatch compilerState editorCode />
17621768 </div >
17631769 </div >
17641770 </div >
0 commit comments