Lazy-load codemirror for bot editing

This commit is contained in:
Jack Kingsman
2026-01-27 17:31:34 -08:00
parent d6e5130f49
commit 6ef6ca4553
11 changed files with 638 additions and 606 deletions
+28
View File
@@ -0,0 +1,28 @@
import CodeMirror from '@uiw/react-codemirror';
import { python } from '@codemirror/lang-python';
import { oneDark } from '@codemirror/theme-one-dark';
interface BotCodeEditorProps {
value: string;
onChange: (value: string) => void;
id?: string;
}
export function BotCodeEditor({ value, onChange, id }: BotCodeEditorProps) {
return (
<CodeMirror
value={value}
onChange={onChange}
extensions={[python()]}
theme={oneDark}
height="256px"
basicSetup={{
lineNumbers: true,
foldGutter: false,
highlightActiveLine: true,
}}
className="rounded-md border border-input overflow-hidden text-sm"
id={id}
/>
);
}
+18 -17
View File
@@ -1,7 +1,8 @@
import { useState, useEffect, useMemo } from 'react';
import CodeMirror from '@uiw/react-codemirror';
import { python } from '@codemirror/lang-python';
import { oneDark } from '@codemirror/theme-one-dark';
import { useState, useEffect, useMemo, lazy, Suspense } from 'react';
const BotCodeEditor = lazy(() =>
import('./BotCodeEditor').then((m) => ({ default: m.BotCodeEditor }))
);
import type {
AppSettings,
AppSettingsUpdate,
@@ -983,19 +984,19 @@ export function SettingsModal({
Reset to Example
</Button>
</div>
<CodeMirror
value={bot.code}
onChange={(code) => handleBotCodeChange(bot.id, code)}
extensions={[python()]}
theme={oneDark}
height="256px"
basicSetup={{
lineNumbers: true,
foldGutter: false,
highlightActiveLine: true,
}}
className="rounded-md border border-input overflow-hidden text-sm"
/>
<Suspense
fallback={
<div className="h-64 rounded-md border border-input bg-[#282c34] flex items-center justify-center text-muted-foreground">
Loading editor...
</div>
}
>
<BotCodeEditor
value={bot.code}
onChange={(code) => handleBotCodeChange(bot.id, code)}
id={`bot-code-${bot.id}`}
/>
</Suspense>
</div>
)}
</div>