Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/app/active-content.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { AccountPage } from "@cocalc/frontend/account/account-page";6import { AdminPage } from "@cocalc/frontend/admin";7import { Alert } from "@cocalc/frontend/antd-bootstrap";8import {9CSS,10React,11useActions,12useTypedRedux,13} from "@cocalc/frontend/app-framework";14import { A } from "@cocalc/frontend/components/A";15import { Icon } from "@cocalc/frontend/components/icon";16import { SiteName } from "@cocalc/frontend/customize";17import { FileUsePage } from "@cocalc/frontend/file-use/page";18import { Connecting } from "@cocalc/frontend/landing-page/connecting";19import { NotificationPage } from "@cocalc/frontend/notifications";20import { ProjectPage } from "@cocalc/frontend/project/page/page";21import { ProjectsPage } from "@cocalc/frontend/projects/projects-page";22import { KioskModeBanner } from "./kiosk-mode-banner";2324const STYLE_SIGNIN_WARNING: CSS = {25textAlign: "center",26width: "max(300px, 50vw)",27marginRight: "auto",28marginLeft: "auto",29marginTop: "50px",30} as const;3132export const ActiveContent: React.FC = React.memo(() => {33const page_actions = useActions("page");3435const active_top_tab = useTypedRedux("page", "active_top_tab");36const fullscreen = useTypedRedux("page", "fullscreen");37const get_api_key = useTypedRedux("page", "get_api_key");38const open_projects = useTypedRedux("projects", "open_projects");3940// initially, we assume a user is signed in – most likely case41const [notSignedIn, setNotSignedIn] = React.useState<boolean>(false);42const is_logged_in = useTypedRedux("account", "is_logged_in");4344React.useEffect(() => {45const timer = setTimeout(() => {46setNotSignedIn(!is_logged_in);47}, 5 * 1000);48return () => clearTimeout(timer);49});5051const showSignInWarning = React.useMemo(() => {52return !is_logged_in && notSignedIn;53}, [is_logged_in, notSignedIn]);5455const v: JSX.Element[] = [];56open_projects?.forEach((project_id: string) => {57const is_active = project_id === active_top_tab;58const x = <ProjectPage project_id={project_id} is_active={is_active} />;59let cls = "smc-vfill";60if (project_id !== active_top_tab) {61cls += " hide";62}63v.push(64<div key={project_id} className={cls}>65{x}66</div>67);68});6970if (get_api_key) {71// Only render the account page which has the message for allowing api access:72return <AccountPage key={"account"} />;73}7475function project_loading() {76// This happens upon loading a URL for a project, but the77// project isn't open yet. Implicitly, this waits for a78// websocket connection. To aid users towards signing up earlier79// we show a warning box about maybe having to sign in.80// https://github.com/sagemathinc/cocalc/issues/609281v.push(<Connecting key={"active-content-connecting"} />);82if (showSignInWarning) {83v.push(84<div key="not-signed-in" style={STYLE_SIGNIN_WARNING}>85<Alert bsStyle="warning" banner={false}>86<Icon style={{ fontSize: "150%" }} name="exclamation-triangle" />87<br />88Your browser has not yet been able to connect to the <SiteName />{" "}89service. You probably have to{" "}90<a91onClick={() => page_actions.set_active_tab("account")}92style={{ fontWeight: "bold" }}93>94sign in95</a>{" "}96first, or otherwise check if you experience{" "}97<A href={"https://doc.cocalc.com/howto/trouble.html"}>98connectivity issues99</A>100.101</Alert>102</div>103);104}105}106107// in kiosk mode: if no file is opened show a banner108if (fullscreen == "kiosk" && v.length === 0) {109v.push(<KioskModeBanner key={"kiosk"} />);110} else {111switch (active_top_tab) {112case "projects":113v.push(<ProjectsPage key={"projects"} />);114break;115case "account":116v.push(<AccountPage key={"account"} />);117break;118case "file-use":119v.push(<FileUsePage key={"file-use"} />);120break;121case "notifications":122v.push(<NotificationPage key={"notifications"} />);123break;124case "admin":125v.push(<AdminPage key={"admin"} />);126break;127case undefined:128v.push(<div key={"broken"}>Please click a button on the top tab.</div>);129break;130}131}132133if (v.length === 0) {134project_loading();135}136137return <>{v}</>;138});139140141