Skip to content

Commit 66dcd7a

Browse files
committed
feat(FileViewer): add dynamic theme support for Monaco Editor
- Import useMemo hook and useThemeStore for theme management - Add theme state subscription from themeStore - Implement monacoTheme computed value with theme detection logic * Maps "light" theme to Monaco's "light" theme * Maps "dark" theme to Monaco's "vs-dark" theme * Detects system preference for "auto" theme mode - Replace hardcoded "vs-dark" theme with dynamic monacoTheme in both Monaco Editor instances - Enables Monaco Editor to respect user theme preferences and system settings
1 parent e8af98c commit 66dcd7a

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

apps/frontend/src/pages/repo/components/FileViewer.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import {
44
EyeIcon,
55
} from "@heroicons/react/24/outline";
66
import MonacoEditor from "@monaco-editor/react";
7-
import type {FC} from "react";
7+
import {useMemo, type FC} from "react";
88
import ReactMarkdown from "react-markdown";
99
import {Button} from "~/components/ui";
10+
import {useThemeStore} from "~/stores/themeStore";
1011

1112
type Props = {
1213
selectedFile: string | null;
@@ -23,6 +24,20 @@ export const FileViewer: FC<Props> = ({
2324
setViewMode,
2425
setSelectedFile,
2526
}) => {
27+
const theme = useThemeStore((s) => s.theme);
28+
29+
const monacoTheme = useMemo(() => {
30+
if (theme === "light") return "light";
31+
if (theme === "dark") return "vs-dark";
32+
// "auto" — check system preference
33+
if (typeof window !== "undefined") {
34+
return window.matchMedia("(prefers-color-scheme: dark)").matches
35+
? "vs-dark"
36+
: "light";
37+
}
38+
return "vs-dark";
39+
}, [theme]);
40+
2641
if (!selectedFile) return null;
2742

2843
const content = fileContent[selectedFile] || "";
@@ -160,7 +175,7 @@ export const FileViewer: FC<Props> = ({
160175
<MonacoEditor
161176
height="100%"
162177
language={language}
163-
theme="vs-dark"
178+
theme={monacoTheme}
164179
value={content}
165180
options={{
166181
readOnly: true,
@@ -191,7 +206,7 @@ export const FileViewer: FC<Props> = ({
191206
<MonacoEditor
192207
height="100%"
193208
language={language}
194-
theme="vs-dark"
209+
theme={monacoTheme}
195210
value={content}
196211
options={{
197212
readOnly: true,

0 commit comments

Comments
 (0)