Skip to content

Commit 7c69293

Browse files
committed
feat: don't show editor button if editor is unavailable
1 parent 75b9592 commit 7c69293

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/components/solvers/SolverConfiguration.tsx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface SolverConfigurationProps {
1616

1717
export const SolverConfiguration = (props: SolverConfigurationProps) => {
1818
const [problemId, setProblemId] = useState<string | null>(null);
19+
const [isEditorReachable, setIsEditorReachable] = useState(true);
1920
const problemGraphViewRef = useRef<HTMLDivElement>(null);
2021

2122
// Reset problemId when problemInput is empty
@@ -32,6 +33,15 @@ export const SolverConfiguration = (props: SolverConfigurationProps) => {
3233
}
3334
}, [problemId]);
3435

36+
useEffect(() => {
37+
const url = process.env.NEXT_PUBLIC_MSS_EDITOR_BASE_URL ?? "";
38+
const controller = new AbortController();
39+
fetch(url, { signal: controller.signal })
40+
.then(() => setIsEditorReachable(true))
41+
.catch(() => setIsEditorReachable(false));
42+
return () => controller.abort();
43+
}, []);
44+
3545
return (
3646
<Flex alignSelf="center">
3747
{problemId === null ? (
@@ -58,17 +68,19 @@ export const SolverConfiguration = (props: SolverConfigurationProps) => {
5868
</Button>
5969
</Tooltip>
6070

61-
<Tooltip label="Create and save a strategy what solvers to use.">
62-
<Link
63-
href={process.env.NEXT_PUBLIC_MSS_EDITOR_BASE_URL}
64-
target="_blank"
65-
>
66-
<Button bg="kitBlue" textColor="white" size="md" gap="5px">
67-
<BsArrowUpRight />
68-
Go to Strategy Editor
69-
</Button>
70-
</Link>
71-
</Tooltip>
71+
{isEditorReachable && (
72+
<Tooltip label="Create and save a strategy what solvers to use.">
73+
<Link
74+
href={process.env.NEXT_PUBLIC_MSS_EDITOR_BASE_URL}
75+
target="_blank"
76+
>
77+
<Button bg="kitBlue" textColor="white" size="md" gap="5px">
78+
<BsArrowUpRight />
79+
Go to Strategy Editor
80+
</Button>
81+
</Link>
82+
</Tooltip>
83+
)}
7284
</HStack>
7385
) : (
7486
<SolverProvider>

0 commit comments

Comments
 (0)