CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/app/settings-modal.tsx
Views: 687
1
/*
2
Easily show a global settings modal at any point in cocalc by doing
3
4
await redux.getActions("page").settings(name)
5
6
This should be used only for various types of configuration that is not
7
specific to a particular project. E.g., many of the panels in the Account
8
tab could also be accessed this way.
9
*/
10
11
import { Modal } from "antd";
12
import { useActions, useRedux } from "@cocalc/frontend/app-framework";
13
import { TerminalSettings } from "@cocalc/frontend/account/terminal-settings";
14
import { EditorSettings } from "@cocalc/frontend/account/editor-settings/editor-settings";
15
16
// Ensure the billing Actions and Store are created, which are needed for purchases, etc., to work...
17
import "@cocalc/frontend/billing/actions";
18
19
export default function SettingsModal({}) {
20
const actions = useActions("page");
21
const name = useRedux("page", "settingsModal");
22
23
if (!name) {
24
return null;
25
}
26
27
const { Component, title } = getDescription(name);
28
29
const close = () => {
30
actions.settings("");
31
};
32
33
// destroyOnClose so values in quota input, etc. get updated
34
return (
35
<Modal
36
key="settings-modal"
37
width={"800px"}
38
destroyOnClose
39
open
40
title={title}
41
onOk={close}
42
onCancel={close}
43
cancelButtonProps={{ style: { display: "none" } }}
44
okText="Close"
45
>
46
<br />
47
{Component != null ? <Component /> : undefined}
48
</Modal>
49
);
50
}
51
52
function getDescription(name: string): { Component?; title? } {
53
switch (name) {
54
case "terminal-settings":
55
return { Component: TerminalSettings };
56
case "editor-settings":
57
return { Component: EditorSettings };
58
default:
59
return {
60
title: <div>Unknown component {name}</div>,
61
};
62
}
63
}
64
65