Add configurable maintenance modal
This commit is contained in:
parent
a9b824e88a
commit
6c370a5956
1
.env
1
.env
@ -6,3 +6,4 @@ REACT_APP_VERSION=$npm_package_version
|
|||||||
REACT_APP_PREVIEW=false
|
REACT_APP_PREVIEW=false
|
||||||
REACT_APP_LOGGING=false
|
REACT_APP_LOGGING=false
|
||||||
REACT_APP_FATHOM_SITE_ID=VMSHBPKD
|
REACT_APP_FATHOM_SITE_ID=VMSHBPKD
|
||||||
|
REACT_APP_MAINTENANCE=true
|
||||||
|
@ -7,3 +7,4 @@ REACT_APP_PREVIEW=false
|
|||||||
REACT_APP_LOGGING=true
|
REACT_APP_LOGGING=true
|
||||||
REACT_APP_FATHOM_SITE_ID=VMSHBPKD
|
REACT_APP_FATHOM_SITE_ID=VMSHBPKD
|
||||||
REACT_APP_SENTRY_DSN=https://d6d22c5233b54c4d91df8fa29d5ffeb0@o467475.ingest.sentry.io/5493956
|
REACT_APP_SENTRY_DSN=https://d6d22c5233b54c4d91df8fa29d5ffeb0@o467475.ingest.sentry.io/5493956
|
||||||
|
REACT_APP_MAINTENANCE=true
|
34
src/modals/MaintenanceModal.tsx
Normal file
34
src/modals/MaintenanceModal.tsx
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { Box, Label, Flex, Button, Text } from "theme-ui";
|
||||||
|
|
||||||
|
import Modal from "../components/Modal";
|
||||||
|
|
||||||
|
import { RequestCloseEventHandler } from "../types/Events";
|
||||||
|
|
||||||
|
type MaintenanceModalProps = {
|
||||||
|
isOpen: boolean;
|
||||||
|
onRequestClose: RequestCloseEventHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
function MaintenanceModal({ isOpen, onRequestClose }: MaintenanceModalProps) {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
isOpen={isOpen}
|
||||||
|
onRequestClose={onRequestClose}
|
||||||
|
style={{ content: { maxWidth: "450px" } }}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Label py={2}>Site under maintenance</Label>
|
||||||
|
<Text as="p" mb={2} variant="caption">
|
||||||
|
Continue offline?
|
||||||
|
</Text>
|
||||||
|
<Flex py={2}>
|
||||||
|
<Button sx={{ flexGrow: 1 }} m={1} ml={0} onClick={onRequestClose}>
|
||||||
|
Ok
|
||||||
|
</Button>
|
||||||
|
</Flex>
|
||||||
|
</Box>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MaintenanceModal;
|
@ -1,4 +1,4 @@
|
|||||||
import io from "socket.io-client";
|
import io, { Socket } from "socket.io-client";
|
||||||
import msgParser from "socket.io-msgpack-parser";
|
import msgParser from "socket.io-msgpack-parser";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
|
|
||||||
@ -33,11 +33,7 @@ class Session extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* The socket io connection
|
* The socket io connection
|
||||||
*/
|
*/
|
||||||
socket = io(process.env.REACT_APP_BROKER_URL!, {
|
socket: Socket;
|
||||||
withCredentials: true,
|
|
||||||
parser: msgParser,
|
|
||||||
transports: ["websocket"],
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A mapping of socket ids to session peers
|
* A mapping of socket ids to session peers
|
||||||
@ -59,6 +55,12 @@ class Session extends EventEmitter {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.peers = {};
|
this.peers = {};
|
||||||
|
this.socket = io(process.env.REACT_APP_BROKER_URL!, {
|
||||||
|
withCredentials: true,
|
||||||
|
parser: msgParser,
|
||||||
|
transports: ["websocket"],
|
||||||
|
autoConnect: process.env.REACT_APP_MAINTENANCE === "false",
|
||||||
|
});
|
||||||
// Signal connected peers of a closure on refresh
|
// Signal connected peers of a closure on refresh
|
||||||
window.addEventListener("beforeunload", this._handleUnload.bind(this));
|
window.addEventListener("beforeunload", this._handleUnload.bind(this));
|
||||||
}
|
}
|
||||||
@ -68,7 +70,11 @@ class Session extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
async connect() {
|
async connect() {
|
||||||
try {
|
try {
|
||||||
if (!process.env.REACT_APP_ICE_SERVERS_URL) {
|
if (
|
||||||
|
!process.env.REACT_APP_ICE_SERVERS_URL ||
|
||||||
|
process.env.REACT_APP_MAINTENANCE === "true"
|
||||||
|
) {
|
||||||
|
this.emit("status", "offline");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const response = await fetch(process.env.REACT_APP_ICE_SERVERS_URL);
|
const response = await fetch(process.env.REACT_APP_ICE_SERVERS_URL);
|
||||||
|
@ -14,6 +14,7 @@ import UpgradingLoadingOverlay from "../components/UpgradingLoadingOverlay";
|
|||||||
import AuthModal from "../modals/AuthModal";
|
import AuthModal from "../modals/AuthModal";
|
||||||
import GameExpiredModal from "../modals/GameExpiredModal";
|
import GameExpiredModal from "../modals/GameExpiredModal";
|
||||||
import ForceUpdateModal from "../modals/ForceUpdateModal";
|
import ForceUpdateModal from "../modals/ForceUpdateModal";
|
||||||
|
import MaintenanceModal from "../modals/MaintenanceModal";
|
||||||
|
|
||||||
import { useAuth } from "../contexts/AuthContext";
|
import { useAuth } from "../contexts/AuthContext";
|
||||||
import { MapStageProvider } from "../contexts/MapStageContext";
|
import { MapStageProvider } from "../contexts/MapStageContext";
|
||||||
@ -38,16 +39,9 @@ function Game() {
|
|||||||
const [session] = useState(new Session());
|
const [session] = useState(new Session());
|
||||||
const [sessionStatus, setSessionStatus] = useState<SessionStatus>();
|
const [sessionStatus, setSessionStatus] = useState<SessionStatus>();
|
||||||
|
|
||||||
useEffect(() => {
|
const [maintenance, setMaintenance] = useState(
|
||||||
async function connect() {
|
process.env.REACT_APP_MAINTENANCE === "true"
|
||||||
await session.connect();
|
);
|
||||||
}
|
|
||||||
connect();
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
session.disconnect();
|
|
||||||
};
|
|
||||||
}, [session]);
|
|
||||||
|
|
||||||
// Handle session errors
|
// Handle session errors
|
||||||
const [peerError, setPeerError] = useState<string | null>(null);
|
const [peerError, setPeerError] = useState<string | null>(null);
|
||||||
@ -106,6 +100,17 @@ function Game() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function connect() {
|
||||||
|
await session.connect();
|
||||||
|
}
|
||||||
|
connect();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
session.disconnect();
|
||||||
|
};
|
||||||
|
}, [session]);
|
||||||
|
|
||||||
// A ref to the Konva stage
|
// A ref to the Konva stage
|
||||||
// the ref will be assigned in the MapInteraction component
|
// the ref will be assigned in the MapInteraction component
|
||||||
const mapStageRef = useRef<Konva.Stage | null>(null);
|
const mapStageRef = useRef<Konva.Stage | null>(null);
|
||||||
@ -159,6 +164,10 @@ function Game() {
|
|||||||
{sessionStatus && databaseStatus === "upgrading" && (
|
{sessionStatus && databaseStatus === "upgrading" && (
|
||||||
<UpgradingLoadingOverlay />
|
<UpgradingLoadingOverlay />
|
||||||
)}
|
)}
|
||||||
|
<MaintenanceModal
|
||||||
|
isOpen={maintenance}
|
||||||
|
onRequestClose={() => setMaintenance(false)}
|
||||||
|
/>
|
||||||
<MapLoadingOverlay />
|
<MapLoadingOverlay />
|
||||||
</MapStageProvider>
|
</MapStageProvider>
|
||||||
</PartyProvider>
|
</PartyProvider>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user