Skip to content

Commit

Permalink
serverTypeFromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Aug 1, 2024
1 parent e4726b6 commit 25e4902
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { CompileContext } from "@SpCompileContext/CompileContext";
export const publicUrl = "https://trom-stan-wasm-server.magland.org";
export const localUrl = "http://localhost:8083";

export type ServerType = "public" | "local" | "custom";
type ServerType = "public" | "local" | "custom";

type CompilationServerConnectionControlProps = {
// none
Expand All @@ -40,12 +40,7 @@ const CompilationServerConnectionControl: FunctionComponent<
retryConnection();
}, [retryConnection]);

const serverLabel =
stanWasmServerUrl === publicUrl
? "public"
: stanWasmServerUrl === localUrl
? "local"
: "custom";
const serverType = serverTypeForUrl(stanWasmServerUrl);

return (
<>
Expand All @@ -58,7 +53,7 @@ const CompilationServerConnectionControl: FunctionComponent<
&nbsp;
<Typography color="white" fontSize={12}>
{isConnected ? "connected to " : "not connected to "}
{serverLabel}
{serverType}
</Typography>
</IconButton>
<CloseableDialog
Expand All @@ -76,6 +71,10 @@ const CompilationServerConnectionControl: FunctionComponent<
);
};

export const serverTypeForUrl = (url: string): ServerType => {
return url === publicUrl ? "public" : url === localUrl ? "local" : "custom";
};

const useIsConnected = (stanWasmServerUrl: string) => {
const probeUrl = `${stanWasmServerUrl}/probe`;
const [isConnected, setIsConnected] = useState<boolean>(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import Radio from "@mui/material/Radio";
import RadioGroup from "@mui/material/RadioGroup";
import TextField from "@mui/material/TextField";
import { FunctionComponent, useCallback, useContext } from "react";
import { localUrl, publicUrl } from "./CompilationServerConnectionControl";

type ServerType = "public" | "local" | "custom";
import {
localUrl,
publicUrl,
serverTypeForUrl,
} from "./CompilationServerConnectionControl";

type ConfigureCompilationServerDialogProps = {
isConnected: boolean;
Expand All @@ -24,12 +26,7 @@ const ConfigureCompilationServerDialog: FunctionComponent<
const { stanWasmServerUrl, setStanWasmServerUrl } =
useContext(CompileContext);

const serverType: ServerType =
stanWasmServerUrl === publicUrl
? "public"
: stanWasmServerUrl === localUrl
? "local"
: "custom";
const serverType = serverTypeForUrl(stanWasmServerUrl);

const makeChoice = useCallback(
(_: unknown, choice: string) => {
Expand Down

0 comments on commit 25e4902

Please sign in to comment.