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/active-content.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { AccountPage } from "@cocalc/frontend/account/account-page";
7
import { AdminPage } from "@cocalc/frontend/admin";
8
import { Alert } from "@cocalc/frontend/antd-bootstrap";
9
import {
10
CSS,
11
React,
12
useActions,
13
useTypedRedux,
14
} from "@cocalc/frontend/app-framework";
15
import { A } from "@cocalc/frontend/components/A";
16
import { Icon } from "@cocalc/frontend/components/icon";
17
import { SiteName } from "@cocalc/frontend/customize";
18
import { FileUsePage } from "@cocalc/frontend/file-use/page";
19
import { Connecting } from "@cocalc/frontend/landing-page/connecting";
20
import { NotificationPage } from "@cocalc/frontend/notifications";
21
import { ProjectPage } from "@cocalc/frontend/project/page/page";
22
import { ProjectsPage } from "@cocalc/frontend/projects/projects-page";
23
import { KioskModeBanner } from "./kiosk-mode-banner";
24
25
const STYLE_SIGNIN_WARNING: CSS = {
26
textAlign: "center",
27
width: "max(300px, 50vw)",
28
marginRight: "auto",
29
marginLeft: "auto",
30
marginTop: "50px",
31
} as const;
32
33
export const ActiveContent: React.FC = React.memo(() => {
34
const page_actions = useActions("page");
35
36
const active_top_tab = useTypedRedux("page", "active_top_tab");
37
const fullscreen = useTypedRedux("page", "fullscreen");
38
const get_api_key = useTypedRedux("page", "get_api_key");
39
const open_projects = useTypedRedux("projects", "open_projects");
40
41
// initially, we assume a user is signed in – most likely case
42
const [notSignedIn, setNotSignedIn] = React.useState<boolean>(false);
43
const is_logged_in = useTypedRedux("account", "is_logged_in");
44
45
React.useEffect(() => {
46
const timer = setTimeout(() => {
47
setNotSignedIn(!is_logged_in);
48
}, 5 * 1000);
49
return () => clearTimeout(timer);
50
});
51
52
const showSignInWarning = React.useMemo(() => {
53
return !is_logged_in && notSignedIn;
54
}, [is_logged_in, notSignedIn]);
55
56
const v: JSX.Element[] = [];
57
open_projects?.forEach((project_id: string) => {
58
const is_active = project_id === active_top_tab;
59
const x = <ProjectPage project_id={project_id} is_active={is_active} />;
60
let cls = "smc-vfill";
61
if (project_id !== active_top_tab) {
62
cls += " hide";
63
}
64
v.push(
65
<div key={project_id} className={cls}>
66
{x}
67
</div>
68
);
69
});
70
71
if (get_api_key) {
72
// Only render the account page which has the message for allowing api access:
73
return <AccountPage key={"account"} />;
74
}
75
76
function project_loading() {
77
// This happens upon loading a URL for a project, but the
78
// project isn't open yet. Implicitly, this waits for a
79
// websocket connection. To aid users towards signing up earlier
80
// we show a warning box about maybe having to sign in.
81
// https://github.com/sagemathinc/cocalc/issues/6092
82
v.push(<Connecting key={"active-content-connecting"} />);
83
if (showSignInWarning) {
84
v.push(
85
<div key="not-signed-in" style={STYLE_SIGNIN_WARNING}>
86
<Alert bsStyle="warning" banner={false}>
87
<Icon style={{ fontSize: "150%" }} name="exclamation-triangle" />
88
<br />
89
Your browser has not yet been able to connect to the <SiteName />{" "}
90
service. You probably have to{" "}
91
<a
92
onClick={() => page_actions.set_active_tab("account")}
93
style={{ fontWeight: "bold" }}
94
>
95
sign in
96
</a>{" "}
97
first, or otherwise check if you experience{" "}
98
<A href={"https://doc.cocalc.com/howto/trouble.html"}>
99
connectivity issues
100
</A>
101
.
102
</Alert>
103
</div>
104
);
105
}
106
}
107
108
// in kiosk mode: if no file is opened show a banner
109
if (fullscreen == "kiosk" && v.length === 0) {
110
v.push(<KioskModeBanner key={"kiosk"} />);
111
} else {
112
switch (active_top_tab) {
113
case "projects":
114
v.push(<ProjectsPage key={"projects"} />);
115
break;
116
case "account":
117
v.push(<AccountPage key={"account"} />);
118
break;
119
case "file-use":
120
v.push(<FileUsePage key={"file-use"} />);
121
break;
122
case "notifications":
123
v.push(<NotificationPage key={"notifications"} />);
124
break;
125
case "admin":
126
v.push(<AdminPage key={"admin"} />);
127
break;
128
case undefined:
129
v.push(<div key={"broken"}>Please click a button on the top tab.</div>);
130
break;
131
}
132
}
133
134
if (v.length === 0) {
135
project_loading();
136
}
137
138
return <>{v}</>;
139
});
140
141