Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/account/config/register.ts
5943 views
1
/*
2
* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import type { IconName } from "@cocalc/frontend/components/icon";
7
8
import { capitalize } from "@cocalc/util/misc";
9
import { register as registerSearch } from "./search/entries";
10
11
export const components: { [main: string]: { [sub: string]: Function } } = {};
12
13
interface Options {
14
path: string;
15
title?: string;
16
icon?: IconName | "ai";
17
desc?: string;
18
Component: Function;
19
danger?: boolean;
20
search?: string | object;
21
}
22
23
interface Entry {
24
title: string;
25
icon?: IconName | "ai";
26
desc?: string;
27
danger?: boolean;
28
}
29
30
export const menu: {
31
[main: string]: {
32
[sub: string]: Entry;
33
};
34
} = {};
35
36
export default function register(opts: Options) {
37
const { path, icon, desc = "", Component, danger, search } = opts;
38
const [main, sub] = path.split("/");
39
const title = opts.title ?? capitalize(sub);
40
41
if (components[main] == null) {
42
components[main] = {};
43
}
44
components[main][sub] = Component;
45
46
if (desc || search) {
47
registerSearch({ path, title, desc, icon, search });
48
}
49
50
if (menu[main] == null) {
51
menu[main] = {};
52
}
53
menu[main][sub] = { title, icon, desc, danger };
54
}
55
56
export const topIcons: { [key: string]: IconName } = {
57
search: "search",
58
account: "user",
59
editor: "edit",
60
system: "gear",
61
licenses: "key",
62
purchases: "credit-card",
63
support: "support",
64
} as const;
65
66