Path: blob/master/src/packages/frontend/app/version-warning.tsx
1496 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { useTypedRedux } from "@cocalc/frontend/app-framework";6import { Gap, Icon } from "@cocalc/frontend/components";7import { type CSSProperties, useEffect, useState } from "react";8import { version } from "@cocalc/util/smc-version";9import { webapp_client } from "@cocalc/frontend/webapp-client";1011const VERSION_WARNING_STYLE = {12fontSize: "12pt",13position: "fixed",14left: 12,15backgroundColor: "#fcf8e3",16color: "#8a6d3b",17top: 20,18borderRadius: 4,19padding: "15px",20zIndex: 900,21boxShadow: "8px 8px 4px #888",22width: "70%",23marginTop: "1em",24} as CSSProperties;2526export default function VersionWarning() {27const [closed, setClosed] = useState<boolean>(false);28const minVersion = useTypedRedux("customize", "version_min_browser");29const recommendedVersion = useTypedRedux(30"customize",31"version_recommended_browser",32);3334useEffect(() => {35if (minVersion > version) {36// immediately and permenantly disconnect user from conat37webapp_client.conat_client.permanentlyDisconnect();38}39}, [minVersion]);4041if (version >= recommendedVersion) {42return null;43}4445if (version >= minVersion && closed) {46return null;47}4849const style = {50...VERSION_WARNING_STYLE,51...(version < minVersion52? { backgroundColor: "red", color: "#fff" }53: undefined),54};5556function render_critical() {57if (version >= minVersion) {58return;59}60return (61<div>62<br />63THIS IS A CRITICAL UPDATE. YOU MUST <Gap />64<a65onClick={() => window.location.reload()}66style={{67cursor: "pointer",68color: "white",69fontWeight: "bold",70textDecoration: "underline",71}}72>73REFRESH THIS PAGE74</a>75<Gap /> IMMEDIATELY. Sorry for the inconvenience.76</div>77);78}7980function render_suggested() {81return (82<>83<Icon name={"refresh"} /> New Version Available: upgrade by <Gap />84<a85onClick={() => window.location.reload()}86style={{87cursor: "pointer",88fontWeight: "bold",89color: style.color,90textDecoration: "underline",91}}92>93reloading this page94</a>95.{render_close()}96</>97);98}99100function render_close() {101if (version >= minVersion) {102return (103<Icon104name="times"105className="pull-right"106style={{ cursor: "pointer", marginTop: "5px" }}107onClick={() => setClosed(true)}108/>109);110}111}112113return (114<div style={style}>115{render_suggested()}116{render_critical()}117</div>118);119}120121122