diff --git a/apps/frontend/components/EditorHeader.tsx b/apps/frontend/components/EditorHeader.tsx index f0f0e24444..8b886a8b29 100644 --- a/apps/frontend/components/EditorHeader.tsx +++ b/apps/frontend/components/EditorHeader.tsx @@ -62,7 +62,7 @@ export default function Editor({ contestId, templateString }: ProblemEditorProps) { - const { language, setLanguage } = useLanguageStore() + const { language, setLanguage } = useLanguageStore(problem.id, contestId)() const { code, setCode } = createCodeStore((state) => state) const testResultStore = useContext(TestResultsContext) if (!testResultStore) throw new Error('TestResultsContext is not provided') diff --git a/apps/frontend/components/EditorResizablePanel.tsx b/apps/frontend/components/EditorResizablePanel.tsx index 666d509a00..d144a5806f 100644 --- a/apps/frontend/components/EditorResizablePanel.tsx +++ b/apps/frontend/components/EditorResizablePanel.tsx @@ -38,7 +38,7 @@ export default function EditorMainResizablePanel({ }: ProblemEditorProps) { const pathname = usePathname() const base = contestId ? `/contest/${contestId}` : '' - const { language, setLanguage } = useLanguageStore() + const { language, setLanguage } = useLanguageStore(problem.id, contestId)() const testResultStore = useContext(TestResultsContext) if (!testResultStore) throw new Error('TestResultsContext is not provided') const { testResults } = useStore(testResultStore) @@ -123,6 +123,8 @@ export default function EditorMainResizablePanel({ > @@ -148,13 +150,17 @@ export default function EditorMainResizablePanel({ } interface CodeEditorInEditorResizablePanelProps { + problemId: number + contestId?: number enableCopyPaste: boolean } function CodeEditorInEditorResizablePanel({ + problemId, + contestId, enableCopyPaste }: CodeEditorInEditorResizablePanelProps) { - const { language } = useLanguageStore() + const { language } = useLanguageStore(problemId, contestId)() const { code, setCode } = createCodeStore() return ( diff --git a/apps/frontend/stores/editor.ts b/apps/frontend/stores/editor.ts index b2b6ed692a..e09035dc44 100644 --- a/apps/frontend/stores/editor.ts +++ b/apps/frontend/stores/editor.ts @@ -8,19 +8,22 @@ interface LanguageStore { setLanguage: (language: Language) => void } -export const useLanguageStore = create( - persist( - (set) => ({ - language: 'C', - setLanguage: (language) => { - set({ language }) +export const useLanguageStore = (problemId: number, contestId?: number) => { + const languageKey = `${problemId}${contestId ? `_${contestId}` : ''}_language` + return create( + persist( + (set) => ({ + language: 'C', + setLanguage: (language) => { + set({ language }) + } + }), + { + name: languageKey } - }), - { - name: 'language' - } + ) ) -) +} interface CodeState { code: string setCode: (code: string) => void