From 168d4b035b7576119f98d736a589cb4764d34c17 Mon Sep 17 00:00:00 2001 From: kachbit Date: Sat, 18 Nov 2023 23:19:34 -0800 Subject: [PATCH 1/5] updated codemirror theme --- frontend/src/components/CodeMirror.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/CodeMirror.tsx b/frontend/src/components/CodeMirror.tsx index 3ba1c51..9f29976 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 } from "thememirror"; import { defaultKeymap, history, @@ -36,7 +36,7 @@ function CodeMirror({ code }: Props) { lineNumbers(), bracketMatching(), html(), - cobalt, + espresso, EditorView.lineWrapping, ], }), @@ -60,6 +60,6 @@ function CodeMirror({ code }: Props) { } }, [code]); - return
; + return
; } export default CodeMirror; From 6f5c0cb0630ab3e16e37c28afa9bd0e647666f5c Mon Sep 17 00:00:00 2001 From: kachbit Date: Sun, 19 Nov 2023 14:30:10 -0800 Subject: [PATCH 2/5] editor theme selector --- frontend/src/App.tsx | 3 ++- frontend/src/components/CodeMirror.tsx | 23 ++++++++++++++------ frontend/src/components/SettingsDialog.tsx | 25 ++++++++++++++++++++++ frontend/src/types.ts | 1 + 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 654acf2..3ba88d3 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 = () => { @@ -231,7 +232,7 @@ function App() { - +
diff --git a/frontend/src/components/CodeMirror.tsx b/frontend/src/components/CodeMirror.tsx index 9f29976..6043fca 100644 --- a/frontend/src/components/CodeMirror.tsx +++ b/frontend/src/components/CodeMirror.tsx @@ -2,6 +2,8 @@ import { useRef, useEffect } from "react"; import { EditorState } from "@codemirror/state"; import { EditorView, keymap, lineNumbers } from "@codemirror/view"; import { espresso } from "thememirror"; +import { cobalt } from "thememirror"; + import { defaultKeymap, history, @@ -14,14 +16,19 @@ 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 +43,7 @@ function CodeMirror({ code }: Props) { lineNumbers(), bracketMatching(), html(), - espresso, + selectedTheme, EditorView.lineWrapping, ], }), @@ -49,9 +56,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 +66,9 @@ function CodeMirror({ code }: Props) { } }, [code]); - return
; + return ( +
+ ); } -export default CodeMirror; + +export default CodeMirror; \ No newline at end of file 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/types.ts b/frontend/src/types.ts index b2c6305..bc66547 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -1,4 +1,5 @@ export interface Settings { openAiApiKey: string | null; isImageGenerationEnabled: boolean; + editorTheme: string; } From 40c00fc12b84fe1d5c6750f9f73a7f66957b1b20 Mon Sep 17 00:00:00 2001 From: kachbit Date: Sun, 19 Nov 2023 15:07:32 -0800 Subject: [PATCH 3/5] added select component --- frontend/src/components/ui/select.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 frontend/src/components/ui/select.tsx 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 ( +