Skip to content

Commit b040fb5

Browse files
committed
Add version switching to settings panel
1 parent a9ef8ad commit b040fb5

File tree

1 file changed

+100
-2
lines changed

1 file changed

+100
-2
lines changed

re_pages/Playground.re

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module DropdownSelect = {
2525
let opacity = disabled ? " opacity-50" : "";
2626
<select
2727
className={
28-
"border border-night-light inline-block rounded px-4 py-1 bg-gray-100 appearance-none font-semibold "
28+
"text-14 bg-transparent border border-night-light inline-block rounded px-4 py-1 font-semibold"
2929
++ opacity
3030
}
3131
name
@@ -1228,9 +1228,33 @@ module Settings = {
12281228
setConfig(defaultConfig);
12291229
};
12301230

1231+
let onCompilerSelect = id => {
1232+
dispatch(
1233+
SwitchToCompiler({id, libraries: readyState.selected.libraries}),
1234+
);
1235+
};
1236+
12311237
let titleClass = "text-18 font-bold mb-2";
12321238
<div className="p-4 pt-8 bg-night-dark text-snow-darker">
12331239
<div>
1240+
<div className=titleClass> "ReScript Version"->s </div>
1241+
<DropdownSelect
1242+
name="compilerVersions"
1243+
value={readyState.selected.id}
1244+
onChange={evt => {
1245+
ReactEvent.Form.preventDefault(evt);
1246+
let id = evt->ReactEvent.Form.target##value;
1247+
onCompilerSelect(id);
1248+
}}>
1249+
{Belt.Array.map(readyState.versions, version => {
1250+
<option className="py-4" key=version value=version>
1251+
version->s
1252+
</option>
1253+
})
1254+
->ate}
1255+
</DropdownSelect>
1256+
</div>
1257+
<div className="mt-6">
12341258
<div className=titleClass> "Syntax"->s </div>
12351259
<ToggleSelection
12361260
values=availableTargetLangs
@@ -1291,6 +1315,8 @@ module ControlPanel = {
12911315
let children =
12921316
switch (state) {
12931317
| Init => "Initializing..."->s
1318+
| SwitchingCompiler(_, _, _) =>
1319+
("Switching Compiler...")->s
12941320
| Compiling(_ready, _)
12951321
| Ready(_ready) =>
12961322
let onFormatClick = evt => {
@@ -1579,7 +1605,9 @@ module OutputPanel = {
15791605
"flex items-center h-12 px-4 pr-16 " ++ activeClass;
15801606
};
15811607

1582-
<div className="h-full bg-night-dark"> <Pane tabs makeTabClass /> </div>;
1608+
<div className="h-full bg-night-dark">
1609+
<Pane selected=2 tabs makeTabClass />
1610+
</div>;
15831611
};
15841612
};
15851613

@@ -1743,6 +1771,76 @@ module Button3 = {
17431771
| _ => [||]
17441772
};
17451773

1774+
let controlPanel =
1775+
switch (compilerState) {
1776+
| Ready(ready)
1777+
| Compiling(ready, _)
1778+
| SwitchingCompiler(ready, _, _) =>
1779+
let availableTargetLangs =
1780+
Api.Version.availableLanguages(ready.selected.apiVersion);
1781+
1782+
let selectedTargetLang =
1783+
switch (ready.targetLang) {
1784+
| Res => (Api.Lang.Res, ready.selected.compilerVersion)
1785+
| Reason => (Reason, ready.selected.reasonVersion)
1786+
| OCaml => (OCaml, ready.selected.ocamlVersion)
1787+
};
1788+
1789+
let onCompilerSelect = id => {
1790+
compilerDispatch(
1791+
SwitchToCompiler({id, libraries: ready.selected.libraries}),
1792+
);
1793+
};
1794+
1795+
let onTargetLangSelect = lang => {
1796+
compilerDispatch(
1797+
SwitchLanguage({lang, code: React.Ref.current(editorCode)}),
1798+
);
1799+
};
1800+
1801+
let onCompileClick = () => {
1802+
compilerDispatch(
1803+
CompileCode(ready.targetLang, React.Ref.current(editorCode)),
1804+
);
1805+
};
1806+
1807+
// When a new compiler version was selected, it should
1808+
// be shown in the control panel as the currently selected
1809+
// version, even when it is currently loading
1810+
let compilerVersion =
1811+
switch (compilerState) {
1812+
| SwitchingCompiler(_, version, _) => version
1813+
| _ => ready.selected.id
1814+
};
1815+
1816+
let onFormatClick = () => {
1817+
compilerDispatch(Format(React.Ref.current(editorCode)));
1818+
};
1819+
1820+
let isCompilerSwitching =
1821+
switch (compilerState) {
1822+
| SwitchingCompiler(_, _, _) => true
1823+
| _ => false
1824+
};
1825+
1826+
<>
1827+
<ControlPanelOld
1828+
isCompilerSwitching
1829+
compilerVersion
1830+
availableTargetLangs
1831+
availableCompilerVersions={ready.versions}
1832+
selectedTargetLang
1833+
loadedLibraries={ready.selected.libraries}
1834+
onCompilerSelect
1835+
onTargetLangSelect
1836+
onCompileClick
1837+
onFormatClick
1838+
/>
1839+
</>;
1840+
| Init => "Initializing"->s
1841+
| SetupFailed(msg) => <> {("Setup failed: " ++ msg)->s} </>
1842+
};
1843+
17461844
<>
17471845
<Meta
17481846
title="ReScript Playground"

0 commit comments

Comments
 (0)