diff --git a/gui/src/app/FileEditor/StanFileEditor.tsx b/gui/src/app/FileEditor/StanFileEditor.tsx index d49a925c..e75e3e7d 100644 --- a/gui/src/app/FileEditor/StanFileEditor.tsx +++ b/gui/src/app/FileEditor/StanFileEditor.tsx @@ -6,13 +6,7 @@ import { ToolbarItem } from "@SpComponents/ToolBar"; import { stancErrorsToCodeMarkers } from "@SpStanc/Linting"; import useStanc from "@SpStanc/useStanc"; import { CompileContext } from "@SpCompileContext/CompileContext"; -import { - FunctionComponent, - useContext, - useEffect, - useMemo, - useState, -} from "react"; +import { FunctionComponent, useContext, useMemo, useState } from "react"; type Props = { fileName: string; @@ -38,17 +32,9 @@ const StanFileEditor: FunctionComponent = ({ setEditedFileContent, ); - const { compileStatus, compileMessage, compile, setValidSyntax } = + const { compileStatus, compileMessage, compile, validSyntax } = useContext(CompileContext); - const validSyntax = useMemo(() => { - return stancErrors.errors === undefined; - }, [stancErrors]); - - useEffect(() => { - setValidSyntax(validSyntax); - }, [validSyntax, setValidSyntax]); - const hasWarnings = useMemo(() => { return stancErrors.warnings && stancErrors.warnings.length > 0; }, [stancErrors]); diff --git a/gui/src/app/Stanc/useStanc.ts b/gui/src/app/Stanc/useStanc.ts index 5cde0fab..cd241919 100644 --- a/gui/src/app/Stanc/useStanc.ts +++ b/gui/src/app/Stanc/useStanc.ts @@ -3,10 +3,11 @@ import { StancReplyMessage, StancWorkerRequests, } from "@SpStanc/Types"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useContext, useEffect, useMemo, useState } from "react"; // https://vitejs.dev/guide/assets#importing-script-as-a-worker // https://vitejs.dev/guide/assets#importing-asset-as-url import stancWorkerURL from "@SpStanc/stancWorker?worker&url"; +import { CompileContext } from "@SpCompileContext/CompileContext"; const useStanc = ( modelName: string, @@ -67,6 +68,14 @@ const useStanc = ( }); }, [modelName, code, stancWorker]); + const { setValidSyntax } = useContext(CompileContext); + const validSyntax = useMemo(() => { + return stancErrors.errors === undefined; + }, [stancErrors]); + useEffect(() => { + setValidSyntax(validSyntax); + }, [validSyntax, setValidSyntax]); + return { stancErrors, requestFormat }; };