|
1 | 1 |
|
2 | 2 | export const Settings = { |
3 | | - view({attrs: {workbench}}) { |
| 3 | + view({attrs: {workbench}, state}) { |
4 | 4 | const currentTheme = workbench.workspace.settings.theme; |
| 5 | + state.selectedTheme = (state.selectedTheme === undefined) ? currentTheme : state.selectedTheme; |
| 6 | + const oninput = (e) => { |
| 7 | + state.selectedTheme = e.target.value; |
| 8 | + } |
5 | 9 | return ( |
6 | 10 | <div class="notice"> |
7 | | - <form method="dialog"> |
8 | | - <h3>Settings</h3> |
9 | | - <div class="flex flex-row"> |
10 | | - <div class="grow">Theme</div> |
11 | | - <div> |
12 | | - <select name="theme"> |
13 | | - <option selected={currentTheme===""} value="">Light</option> |
14 | | - <option selected={currentTheme==="darkmode"} value="darkmode">Dark</option> |
15 | | - <option selected={currentTheme==="sepia"} value="sepia">Sepia</option> |
16 | | - <option selected={currentTheme==="sublime"} value="sublime">Sublime</option> |
17 | | - </select> |
18 | | - </div> |
| 11 | + <h3>Settings</h3> |
| 12 | + <div class="flex flex-row"> |
| 13 | + <div class="grow">Theme</div> |
| 14 | + <div> |
| 15 | + <select name="theme" oninput={oninput}> |
| 16 | + <option selected={state.selectedTheme===""} value="">Light</option> |
| 17 | + <option selected={state.selectedTheme==="darkmode"} value="darkmode">Dark</option> |
| 18 | + <option selected={state.selectedTheme==="sepia"} value="sepia">Sepia</option> |
| 19 | + <option selected={state.selectedTheme==="sublime"} value="sublime">Sublime</option> |
| 20 | + </select> |
19 | 21 | </div> |
20 | | - <div class="button-bar"> |
21 | | - <button onclick={() => { |
| 22 | + </div> |
| 23 | + <div class="button-bar"> |
| 24 | + <button onclick={() => { |
| 25 | + workbench.closeDialog(); |
| 26 | + }}>Cancel</button> |
| 27 | + <button class="primary" onclick={async (e) => { |
| 28 | + if (currentTheme !== state.selectedTheme) { |
| 29 | + workbench.workspace.settings.theme = state.selectedTheme; |
| 30 | + await workbench.workspace.save(true); |
| 31 | + location.reload(); |
| 32 | + } else { |
22 | 33 | workbench.closeDialog(); |
23 | | - }}>Cancel</button> |
24 | | - <button class="primary" onclick={async (e) => { |
25 | | - let newTheme = e.target.closest("form").elements[0].value; |
26 | | - if (currentTheme !== newTheme) { |
27 | | - workbench.workspace.settings.theme = newTheme; |
28 | | - await workbench.workspace.save(true); |
29 | | - location.reload(); |
30 | | - } else { |
31 | | - workbench.closeDialog(); |
32 | | - } |
33 | | - }}>Save Changes</button> |
34 | | - </div> |
35 | | - </form> |
| 34 | + } |
| 35 | + }}>Save Changes</button> |
| 36 | + </div> |
36 | 37 | </div> |
37 | 38 | ) |
38 | 39 | } |
|
0 commit comments