diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 654acf2..f579882 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -34,6 +34,7 @@ function App() { const [settings, setSettings] = useState({ openAiApiKey: null, isImageGenerationEnabled: true, + editorTheme: "cobalt" }); const downloadCode = () => { @@ -180,7 +181,6 @@ function App() { Original Screenshot -

Console @@ -231,7 +231,7 @@ function App() { - +

diff --git a/frontend/src/components/CodeMirror.tsx b/frontend/src/components/CodeMirror.tsx index 3ba1c51..21008bc 100644 --- a/frontend/src/components/CodeMirror.tsx +++ b/frontend/src/components/CodeMirror.tsx @@ -1,7 +1,7 @@ import { useRef, useEffect } from "react"; import { EditorState } from "@codemirror/state"; import { EditorView, keymap, lineNumbers } from "@codemirror/view"; -import { cobalt } from "thememirror"; +import { espresso, cobalt } from "thememirror"; import { defaultKeymap, history, @@ -14,14 +14,18 @@ import { html } from "@codemirror/lang-html"; interface Props { code: string; + editorTheme: string; } -function CodeMirror({ code }: Props) { +function CodeMirror({ code, editorTheme }: Props) { const ref = useRef(null); const view = useRef(null); - // Initialize the editor when the component mounts useEffect(() => { + let selectedTheme = cobalt; + if (editorTheme === "espresso") { + selectedTheme = espresso; + } view.current = new EditorView({ state: EditorState.create({ doc: code, @@ -36,7 +40,7 @@ function CodeMirror({ code }: Props) { lineNumbers(), bracketMatching(), html(), - cobalt, + selectedTheme, EditorView.lineWrapping, ], }), @@ -49,9 +53,8 @@ function CodeMirror({ code }: Props) { view.current = null; } }; - }, []); + }, [code, editorTheme]); - // Update the contents of the editor when the code changes useEffect(() => { if (view.current && view.current.state.doc.toString() !== code) { view.current.dispatch({ @@ -60,6 +63,9 @@ function CodeMirror({ code }: Props) { } }, [code]); - return
; + return ( +
+ ); } + export default CodeMirror; diff --git a/frontend/src/components/SettingsDialog.tsx b/frontend/src/components/SettingsDialog.tsx index 512894f..33dd401 100644 --- a/frontend/src/components/SettingsDialog.tsx +++ b/frontend/src/components/SettingsDialog.tsx @@ -1,3 +1,4 @@ +import React from "react"; import { Dialog, DialogClose, @@ -12,6 +13,7 @@ import { Settings } from "../types"; import { Switch } from "./ui/switch"; import { Label } from "./ui/label"; import { Input } from "./ui/input"; +import { Select } from "./ui/select"; interface Props { settings: Settings; @@ -19,6 +21,13 @@ interface Props { } function SettingsDialog({ settings, setSettings }: Props) { + const handleThemeChange = (theme: string) => { + setSettings((s) => ({ + ...s, + editorTheme: theme, + })); + }; + return ( @@ -65,7 +74,23 @@ function SettingsDialog({ settings, setSettings }: Props) { })) } /> + +
+ +
+ Save diff --git a/frontend/src/components/ui/select.tsx b/frontend/src/components/ui/select.tsx new file mode 100644 index 0000000..6d4d943 --- /dev/null +++ b/frontend/src/components/ui/select.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { cn } from "@/lib/utils"; + +export interface SelectProps + extends React.SelectHTMLAttributes {} + +const Select = React.forwardRef( + ({ className, ...props }, ref) => { + return ( +