mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(code-editor): use Zustand state for dynamic language selection
This commit is contained in:
parent
1bc1b638e2
commit
6329babfca
@ -7,6 +7,7 @@ import normalizeUrl from "normalize-url";
|
|||||||
import { highlighter } from "@/lib/shiki";
|
import { highlighter } from "@/lib/shiki";
|
||||||
import { shikiToMonaco } from "@shikijs/monaco";
|
import { shikiToMonaco } from "@shikijs/monaco";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { useCodeEditorState } from "@/store/useCodeEditor";
|
||||||
import { CODE_EDITOR_OPTIONS } from "@/constants/code-editor-options";
|
import { CODE_EDITOR_OPTIONS } from "@/constants/code-editor-options";
|
||||||
import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from "vscode-ws-jsonrpc";
|
import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from "vscode-ws-jsonrpc";
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ const DynamicEditor = dynamic(
|
|||||||
|
|
||||||
export default function CodeEditor() {
|
export default function CodeEditor() {
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
|
const { language } = useCodeEditorState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const lspUrl = process.env.NEXT_PUBLIC_LSP_C_URL || "ws://localhost:4594/clangd";
|
const lspUrl = process.env.NEXT_PUBLIC_LSP_C_URL || "ws://localhost:4594/clangd";
|
||||||
@ -73,14 +75,10 @@ export default function CodeEditor() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DynamicEditor
|
<DynamicEditor
|
||||||
defaultLanguage="c"
|
defaultLanguage={language}
|
||||||
defaultValue="# include<stdio.h>"
|
defaultValue="# include<stdio.h>"
|
||||||
path="file:///main.c"
|
path="file:///main.c"
|
||||||
theme={
|
theme={resolvedTheme === "light" ? "github-light-default" : "github-dark-default"}
|
||||||
resolvedTheme === "light"
|
|
||||||
? "github-light-default"
|
|
||||||
: "github-dark-default"
|
|
||||||
}
|
|
||||||
height="100%"
|
height="100%"
|
||||||
options={CODE_EDITOR_OPTIONS}
|
options={CODE_EDITOR_OPTIONS}
|
||||||
beforeMount={(monaco) => {
|
beforeMount={(monaco) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user