Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move validSyntax logic inside useStanc #196

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions gui/src/app/FileEditor/StanFileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,17 +32,9 @@ const StanFileEditor: FunctionComponent<Props> = ({
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]);
Expand Down
11 changes: 10 additions & 1 deletion gui/src/app/Stanc/useStanc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 };
};

Expand Down