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/components/loading.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 { CSSProperties } from "react";
7
import { useIntl } from "react-intl";
8
9
import { TypedMap, useDelayedRender } from "@cocalc/frontend/app-framework";
10
import { labels } from "@cocalc/frontend/i18n";
11
import { Icon } from "./icon";
12
13
export type Estimate = TypedMap<{
14
time: number; // Time in seconds
15
type: "new" | "ready" | "archived";
16
}>;
17
export const Estimate = null; // webpack + TS es2020 modules need this
18
19
interface Props {
20
style?: CSSProperties;
21
text?: string;
22
estimate?: Estimate;
23
theme?: "medium" | undefined;
24
delay?: 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.
25
transparent?: boolean;
26
}
27
28
const LOADING_THEMES: { [keys: string]: CSSProperties } = {
29
medium: {
30
fontSize: "24pt",
31
textAlign: "center",
32
marginTop: "15px",
33
color: "#888",
34
background: "white",
35
},
36
} as const;
37
38
export function Loading({
39
style,
40
text,
41
estimate,
42
theme,
43
delay,
44
transparent = false,
45
}: Props) {
46
const intl = useIntl();
47
48
const render = useDelayedRender(delay ?? 0);
49
if (!render) {
50
return <></>;
51
}
52
53
return (
54
<div
55
style={{
56
...(theme ? LOADING_THEMES[theme] : undefined),
57
...(transparent ? { background: "transparent" } : undefined),
58
...style,
59
}}
60
>
61
<span>
62
<Icon name="cocalc-ring" spin />{" "}
63
{text ?? intl.formatMessage(labels.loading)}
64
</span>
65
{estimate != undefined && (
66
<div>
67
Loading '{estimate.get("type")}' file.
68
<br />
69
Estimated time: {estimate.get("time")}s
70
</div>
71
)}
72
</div>
73
);
74
}
75
76