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

Make user confirm on first upload #242

Merged
merged 2 commits into from
Nov 4, 2024
Merged
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
27 changes: 27 additions & 0 deletions gui/src/app/Compilation/Context/CompileContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ const useIsConnected = (stanWasmServerUrl: string) => {
const initialStanWasmServerUrl =
localStorage.getItem("stanWasmServerUrl") || publicCompilationServerUrl;

const showOneTimeMessage = (url: string) => {
if (url !== publicCompilationServerUrl) {
// if the user opted in to a custom URL, we assume they are good with it...
return true;
}

const alreadyConfirmed = "compileModelUploadMessage";
if (localStorage.getItem(alreadyConfirmed) === "true") {
return true;
}
if (
window.confirm(
"This will upload the main.stan file to the server " +
"for compilation. All other files remain local.\n" +
"Do you want to continue? (If you accept, this message will not be shown again.)",
)
) {
localStorage.setItem(alreadyConfirmed, "true");
return true;
}
return false;
};

export const CompileContextProvider: FunctionComponent<
PropsWithChildren<CompileContextProviderProps>
> = ({ children }) => {
Expand Down Expand Up @@ -86,6 +109,10 @@ export const CompileContextProvider: FunctionComponent<
}, [stanWasmServerUrl]);

const handleCompile = useCallback(async () => {
if (!showOneTimeMessage(stanWasmServerUrl)) {
return;
}

setCompileStatus("compiling");
await new Promise((resolve) => setTimeout(resolve, 500)); // for effect
const onStatus = (msg: string) => {
Expand Down