@@ -1130,21 +1130,27 @@ module ControlPanel = {
1130
1130
~state : CompilerManagerHook .state ,
1131
1131
~dispatch : CompilerManagerHook .action => unit ,
1132
1132
~editorCode : React .ref <string >,
1133
- ~runOutput ,
1134
- ~toggleRunOutput ,
1135
1133
) => {
1136
1134
let children = switch state {
1137
1135
| Init => React .string ("Initializing..." )
1138
1136
| SwitchingCompiler (_ready , _version ) => React .string ("Switching Compiler..." )
1139
- | Compiling (_ , _ )
1137
+ | Compiling (_ )
1138
+ | Executing (_ )
1140
1139
| Ready (_ ) =>
1141
1140
let onFormatClick = evt => {
1142
1141
ReactEvent .Mouse .preventDefault (evt )
1143
1142
dispatch (Format (editorCode .current ))
1144
1143
}
1145
1144
1145
+ let autoRun = switch state {
1146
+ | CompilerManagerHook .Executing ({state : {autoRun : true }})
1147
+ | Compiling ({autoRun : true })
1148
+ | Ready ({autoRun : true }) => true
1149
+ | _ => false
1150
+ }
1151
+
1146
1152
<div className = "flex flex-row gap-x-2" >
1147
- <ToggleButton checked = runOutput onChange = {_ => toggleRunOutput ( )}>
1153
+ <ToggleButton checked = autoRun onChange = {_ => dispatch ( ToggleAutoRun )}>
1148
1154
{React .string ("Auto-run" )}
1149
1155
</ToggleButton >
1150
1156
<Button onClick = onFormatClick > {React .string ("Format" )} </Button >
@@ -1176,7 +1182,6 @@ module OutputPanel = {
1176
1182
~compilerState : CompilerManagerHook .state ,
1177
1183
~editorCode : React .ref <string >,
1178
1184
~currentTab : tab ,
1179
- ~runOutput ,
1180
1185
) => {
1181
1186
/*
1182
1187
We need the prevState to understand different
@@ -1199,8 +1204,9 @@ module OutputPanel = {
1199
1204
}
1200
1205
| (_ , Ready ({result : Comp (Success (_ )) as result })) =>
1201
1206
ControlPanel .codeFromResult (result )-> Some
1202
- | (Ready ({result : Comp (Success (_ )) as result }), Compiling (_ , _ )) =>
1207
+ | (Ready ({result : Comp (Success (_ )) as result }), Compiling (_ )) =>
1203
1208
ControlPanel .codeFromResult (result )-> Some
1209
+ | (_ , Executing ({jsCode })) => Some (jsCode )
1204
1210
| _ => None
1205
1211
}
1206
1212
| None =>
@@ -1213,8 +1219,9 @@ module OutputPanel = {
1213
1219
prevState .current = Some (compilerState )
1214
1220
1215
1221
let resultPane = switch compilerState {
1216
- | Compiling (ready , _ )
1217
- | Ready (ready ) =>
1222
+ | Compiling (ready )
1223
+ | Ready (ready )
1224
+ | Executing ({state : ready }) =>
1218
1225
switch ready .result {
1219
1226
| Comp (Success (_ ))
1220
1227
| Conv (Success (_ )) => React .null
@@ -1246,8 +1253,9 @@ module OutputPanel = {
1246
1253
</div >
1247
1254
1248
1255
let errorPane = switch compilerState {
1249
- | Compiling (ready , _ )
1256
+ | Compiling (ready )
1250
1257
| Ready (ready )
1258
+ | Executing ({state : ready })
1251
1259
| SwitchingCompiler (ready , _ ) =>
1252
1260
<ResultPane
1253
1261
targetLang = ready .targetLang
@@ -1260,7 +1268,8 @@ module OutputPanel = {
1260
1268
1261
1269
let settingsPane = switch compilerState {
1262
1270
| Ready (ready )
1263
- | Compiling (ready , _ )
1271
+ | Compiling (ready )
1272
+ | Executing ({state : ready })
1264
1273
| SwitchingCompiler (ready , _ ) =>
1265
1274
let config = ready .selected .config
1266
1275
let setConfig = config => compilerDispatch (UpdateConfig (config ))
@@ -1273,7 +1282,9 @@ module OutputPanel = {
1273
1282
let prevSelected = React .useRef (0 )
1274
1283
1275
1284
let selected = switch compilerState {
1276
- | Compiling (_ , _ ) => prevSelected .current
1285
+ | Executing (_ )
1286
+ | Compiling (_ ) =>
1287
+ prevSelected .current
1277
1288
| Ready (ready ) =>
1278
1289
switch ready .result {
1279
1290
| Comp (Success (_ ))
@@ -1285,10 +1296,10 @@ module OutputPanel = {
1285
1296
1286
1297
prevSelected .current = selected
1287
1298
1288
- let ( logs , setLogs ) = React . useState ( _ => [] )
1299
+ let appendLog = ( level , content ) => compilerDispatch ( AppendLog ({ level , content }) )
1289
1300
1290
1301
let tabs = [
1291
- (Output , <OutputPanel runOutput compilerState logs setLogs />),
1302
+ (Output , <OutputPanel compilerState appendLog />),
1292
1303
(JavaScript , output ),
1293
1304
(Problems , errorPane ),
1294
1305
(Settings , settingsPane ),
@@ -1483,7 +1494,7 @@ let make = (~versions: array<string>) => {
1483
1494
}
1484
1495
1485
1496
None
1486
- }, [ compilerState ] )
1497
+ }, ( compilerState , compilerDispatch ) )
1487
1498
1488
1499
let (layout , setLayout ) = React .useState (_ =>
1489
1500
Webapi .Window .innerWidth < breakingPoint ? Column : Row
@@ -1693,17 +1704,12 @@ let make = (~versions: array<string>) => {
1693
1704
</button >
1694
1705
})
1695
1706
1696
- let (runOutput , setRunOutput ) = React .useState (() => false )
1697
- let toggleRunOutput = () => setRunOutput (prev => ! prev )
1698
-
1699
1707
<main className = {"flex flex-col bg-gray-100 overflow-hidden" }>
1700
1708
<ControlPanel
1701
1709
actionIndicatorKey = {Int .toString (actionCount )}
1702
1710
state = compilerState
1703
1711
dispatch = compilerDispatch
1704
1712
editorCode
1705
- runOutput
1706
- toggleRunOutput
1707
1713
/>
1708
1714
<div
1709
1715
className = {` flex ${layout == Column ? "flex-col" : "flex-row" }` }
@@ -1758,7 +1764,7 @@ let make = (~versions: array<string>) => {
1758
1764
{React .array (headers )}
1759
1765
</div >
1760
1766
<div ref = {ReactDOM .Ref .domRef (subPanelRef )} className = "overflow-auto" >
1761
- <OutputPanel currentTab compilerDispatch compilerState editorCode runOutput />
1767
+ <OutputPanel currentTab compilerDispatch compilerState editorCode />
1762
1768
</div >
1763
1769
</div >
1764
1770
</div >
0 commit comments