Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/course/compute/index.tsx
1697 views
1
import { Button } from "antd";
2
import { useMemo, useState } from "react";
3
import { Icon } from "@cocalc/frontend/components/icon";
4
import type { ComputeServerConfig } from "../types";
5
import type { CourseActions } from "../actions";
6
import type { Unit } from "../store";
7
import ComputeServer from "@cocalc/frontend/compute/inline";
8
import ComputeServerModal from "./modal";
9
10
interface Props {
11
style?;
12
actions: CourseActions;
13
unit: Unit;
14
}
15
16
export function ComputeServerButton({ style, actions, unit }: Props) {
17
const [open, setOpen] = useState<boolean>(false);
18
const config: ComputeServerConfig = useMemo(() => {
19
return unit.get("compute_server")?.toJS() ?? {};
20
}, [unit]);
21
22
return (
23
<>
24
<Button
25
style={style}
26
onClick={() => {
27
setOpen(!open);
28
}}
29
>
30
<Icon name="server" />
31
{!!config.server_id ? (
32
<ComputeServer id={config.server_id} titleOnly />
33
) : (
34
"Compute Server..."
35
)}
36
</Button>
37
{open && (
38
<ComputeServerModal
39
unit={unit}
40
onClose={() => setOpen(false)}
41
actions={actions}
42
/>
43
)}
44
</>
45
);
46
}
47
48