Skip to content

Commit

Permalink
Merge pull request #242 from flatironinstitute/ask-before-first-upload
Browse files Browse the repository at this point in the history
Make user confirm on first upload
  • Loading branch information
WardBrian authored Nov 4, 2024
2 parents 7b7e63d + 3d182c7 commit 7ffaa63
Showing 1 changed file with 27 additions and 0 deletions.
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

0 comments on commit 7ffaa63

Please sign in to comment.