Skip to content

Commit 548ce54

Browse files
committed
Remove CodeMirror wrapper
1 parent ad814a6 commit 548ce54

File tree

3 files changed

+24
-52
lines changed

3 files changed

+24
-52
lines changed

frontend/src/component/common/CodeMirror.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

frontend/src/component/config/ConfigEditor.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { createResource, createSignal, getOwner, runWithOwner } from "solid-js";
1+
import { createEffect, createResource, createSignal, getOwner, on, runWithOwner } from "solid-js";
22
import { baseExtensions } from ".";
33
import { getGuildConfig, writeGuildConfig } from "../../client";
44
import { account } from "../../state/account";
55
import { useGuild } from "../../state/guilds";
6-
import { CodeMirror } from "../common/CodeMirror";
76
import { StatusFallback } from "../common/StatusFallback";
87
import { Button } from "../common/Button";
98
import { EditorView } from "codemirror";
@@ -19,13 +18,12 @@ export function ConfigEditor(props: { guildID: string; plugin: string; }) {
1918
return undefined;
2019
});
2120

22-
23-
let view: EditorView;
24-
2521
const [saving, setSaving] = createSignal(false);
2622
const saveDisabled = () => saving() || resource.loading || resource() === undefined;
2723

28-
const save = async () => {
24+
const owner = getOwner();
25+
26+
const save = () => runWithOwner(owner, async () => {
2927
setSaving(true);
3028

3129
const lastLine = view.state.doc.line(view.state.doc.lines).text;
@@ -47,22 +45,28 @@ export function ConfigEditor(props: { guildID: string; plugin: string; }) {
4745
} finally {
4846
setSaving(false);
4947
}
50-
};
48+
});
5149

52-
const owner = getOwner();
50+
const view = new EditorView({
51+
extensions: baseExtensions({
52+
save: () => (save(), true)
53+
})
54+
});
55+
56+
createEffect(on(resource, () => {
57+
view.update([
58+
view.state.update({
59+
changes: { from: 0, to: view.state.doc.length, insert: resource() }
60+
})
61+
]);
62+
}, { defer: true }));
5363

5464
return (
5565
<div class="configEditor">
5666
<div class="hbox">
57-
<Button color="success" onClick={() => runWithOwner(owner, save)} disabled={saveDisabled()} icon={IconDeviceFloppy}>Save</Button>
67+
<Button color="success" onClick={save} disabled={saveDisabled()} icon={IconDeviceFloppy}>Save</Button>
5868
</div>
59-
<StatusFallback resource={resource}>
60-
<CodeMirror
61-
value={resource()!}
62-
viewRef={v => view = v}
63-
extensions={baseExtensions(() => (runWithOwner(owner, save), true))}
64-
/>
65-
</StatusFallback>
69+
<StatusFallback resource={resource}>{view.dom}</StatusFallback>
6670
</div>
6771
);
6872
}

frontend/src/component/config/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ const toml = LRLanguage.define({
1616
}
1717
});
1818

19-
export function baseExtensions(saveAction: Command) {
19+
export function baseExtensions(options: {
20+
save: Command
21+
}) {
2022
return [
2123
basicSetup,
2224
toml,
@@ -27,7 +29,7 @@ export function baseExtensions(saveAction: Command) {
2729
}]),
2830
keymap.of([{
2931
key: "Mod-s",
30-
run: saveAction,
32+
run: options.save,
3133
}]),
3234
indentUnit.of("\t"),
3335
gruvboxDark,

0 commit comments

Comments
 (0)