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/warnings.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 { React, redux, TypedMap } from "@cocalc/frontend/app-framework";
7
import { Gap, Icon } from "@cocalc/frontend/components";
8
import { SiteName } from "@cocalc/frontend/customize";
9
import { get_browser } from "@cocalc/frontend/feature";
10
import { webapp_client } from "@cocalc/frontend/webapp-client";
11
12
interface VersionWarningProps {
13
new_version: TypedMap<{ min_version: number; version: number }>;
14
}
15
16
const VERSION_WARNING_STYLE: React.CSSProperties = {
17
fontSize: "12pt",
18
position: "fixed",
19
left: 12,
20
backgroundColor: "#fcf8e3",
21
color: "#8a6d3b",
22
top: 20,
23
borderRadius: 4,
24
padding: "15px",
25
zIndex: 900,
26
boxShadow: "8px 8px 4px #888",
27
width: "70%",
28
marginTop: "1em",
29
} as const;
30
31
export const VersionWarning: React.FC<VersionWarningProps> = React.memo(
32
({ new_version }) => {
33
function render_critical() {
34
if (new_version.get("min_version") <= webapp_client.version()) {
35
return;
36
}
37
return (
38
<div>
39
<br />
40
THIS IS A CRITICAL UPDATE. YOU MUST <Gap />
41
<a
42
onClick={() => window.location.reload()}
43
style={{
44
cursor: "pointer",
45
color: "white",
46
fontWeight: "bold",
47
textDecoration: "underline",
48
}}
49
>
50
RELOAD THIS PAGE
51
</a>
52
<Gap /> IMMEDIATELY OR YOU WILL BE DISCONNECTED. Sorry for the
53
inconvenience.
54
</div>
55
);
56
}
57
58
function render_close() {
59
if (new_version.get("min_version") <= webapp_client.version()) {
60
return (
61
<Icon
62
name="times"
63
className="pull-right"
64
style={{ cursor: "pointer" }}
65
onClick={() => redux.getActions("page").set_new_version(undefined)}
66
/>
67
);
68
}
69
}
70
71
let style: React.CSSProperties = VERSION_WARNING_STYLE;
72
if (new_version.get("min_version") > webapp_client.version()) {
73
style = { ...style, ...{ backgroundColor: "red", color: "#fff" } };
74
}
75
76
return (
77
<div style={style}>
78
<Icon name={"refresh"} /> New Version Available: upgrade by <Gap />
79
<a
80
onClick={() => window.location.reload()}
81
style={{
82
cursor: "pointer",
83
fontWeight: "bold",
84
color: style.color,
85
textDecoration: "underline",
86
}}
87
>
88
reloading this page
89
</a>
90
.{render_close()}
91
{render_critical()}
92
</div>
93
);
94
},
95
);
96
97
const WARNING_STYLE: React.CSSProperties = {
98
position: "fixed",
99
left: 12,
100
backgroundColor: "red",
101
color: "#fff",
102
top: 20,
103
opacity: 0.9,
104
borderRadius: 4,
105
padding: 5,
106
marginTop: "1em",
107
zIndex: 100000,
108
boxShadow: "8px 8px 4px #888",
109
width: "70%",
110
} as const;
111
112
export const CookieWarning: React.FC = React.memo(() => {
113
return (
114
<div style={WARNING_STYLE}>
115
<Icon name="warning" /> You <em>must</em> enable cookies to use{" "}
116
<SiteName />.
117
</div>
118
);
119
});
120
121
const STORAGE_WARNING_STYLE: React.CSSProperties = {
122
...WARNING_STYLE,
123
top: 55,
124
};
125
126
export const LocalStorageWarning: React.FC = React.memo(() => {
127
return (
128
<div style={STORAGE_WARNING_STYLE}>
129
<Icon name="warning" /> You <em>must</em> enable local storage to use{" "}
130
<SiteName />
131
{get_browser() === "safari"
132
? " (on Safari you must disable private browsing mode)"
133
: undefined}
134
.
135
</div>
136
);
137
});
138
139