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/components/loading.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { CSSProperties } from "react";6import { useIntl } from "react-intl";78import { TypedMap, useDelayedRender } from "@cocalc/frontend/app-framework";9import { labels } from "@cocalc/frontend/i18n";10import { Icon } from "./icon";1112export type Estimate = TypedMap<{13time: number; // Time in seconds14type: "new" | "ready" | "archived";15}>;16export const Estimate = null; // webpack + TS es2020 modules need this1718interface Props {19style?: CSSProperties;20text?: string;21estimate?: Estimate;22theme?: "medium" | undefined;23delay?: number; // if given, don't show anything until after delay milliseconds. The component could easily unmount by then, and hence never annoyingly flicker on screen.24transparent?: boolean;25}2627const LOADING_THEMES: { [keys: string]: CSSProperties } = {28medium: {29fontSize: "24pt",30textAlign: "center",31marginTop: "15px",32color: "#888",33background: "white",34},35} as const;3637export function Loading({38style,39text,40estimate,41theme,42delay,43transparent = false,44}: Props) {45const intl = useIntl();4647const render = useDelayedRender(delay ?? 0);48if (!render) {49return <></>;50}5152return (53<div54style={{55...(theme ? LOADING_THEMES[theme] : undefined),56...(transparent ? { background: "transparent" } : undefined),57...style,58}}59>60<span>61<Icon name="cocalc-ring" spin />{" "}62{text ?? intl.formatMessage(labels.loading)}63</span>64{estimate != undefined && (65<div>66Loading '{estimate.get("type")}' file.67<br />68Estimated time: {estimate.get("time")}s69</div>70)}71</div>72);73}747576