Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions site/src/pages/TerminalPage/TerminalPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { makeStyles } from "@material-ui/core/styles"
import { useMachine } from "@xstate/react"
import { Stack } from "components/Stack/Stack"
import { FC, useEffect, useRef, useState } from "react"
import { Helmet } from "react-helmet-async"
import { useNavigate, useParams, useSearchParams } from "react-router-dom"
Expand All @@ -19,6 +20,34 @@ export const Language = {
websocketErrorMessagePrefix: "WebSocket failed: ",
}

const useReloading = (isDisconnected: boolean) => {
const [status, setStatus] = useState<"reloading" | "notReloading">(
"notReloading",
)

// Retry connection on key press when it is disconnected
useEffect(() => {
if (!isDisconnected) {
return
}

const keyDownHandler = () => {
setStatus("reloading")
window.location.reload()
}

document.addEventListener("keydown", keyDownHandler)

return () => {
document.removeEventListener("keydown", keyDownHandler)
}
}, [isDisconnected])

return {
status,
}
}

const TerminalPage: FC<
React.PropsWithChildren<{
readonly renderer?: XTerm.RendererType
Expand Down Expand Up @@ -67,6 +96,7 @@ const TerminalPage: FC<
workspaceAgent,
websocketError,
} = terminalState.context
const reloading = useReloading(isDisconnected)

// Create the terminal!
useEffect(() => {
Expand Down Expand Up @@ -216,7 +246,16 @@ const TerminalPage: FC<
{/* This overlay makes it more obvious that the terminal is disconnected. */}
{/* It's nice for situations where Coder restarts, and they are temporarily disconnected. */}
<div className={`${styles.overlay} ${isDisconnected ? "" : "connected"}`}>
<span className={styles.overlayText}>Disconnected</span>
{reloading.status === "reloading" ? (
<span className={styles.overlayText}>Reloading...</span>
) : (
<Stack spacing={0.5} alignItems="center">
<span className={styles.overlayText}>Disconnected</span>
<span className={styles.overlaySubtext}>
Press any key to retry
</span>
</Stack>
)}
</div>
<div className={styles.terminal} ref={xtermRef} data-testid="terminal" />
</>
Expand All @@ -225,7 +264,7 @@ const TerminalPage: FC<

export default TerminalPage

const useStyles = makeStyles(() => ({
const useStyles = makeStyles((theme) => ({
overlay: {
position: "absolute",
pointerEvents: "none",
Expand All @@ -238,17 +277,20 @@ const useStyles = makeStyles(() => ({
justifyContent: "center",
display: "flex",
color: "white",
fontFamily: MONOSPACE_FONT_FAMILY,
fontSize: 18,
fontSize: 16,
backgroundColor: "rgba(0, 0, 0, 0.6)",
backdropFilter: "blur(4px)",
"&.connected": {
opacity: 0,
},
},
overlayText: {
padding: 32,
fontSize: 24,
backgroundColor: "#000",
fontSize: 16,
fontWeight: 600,
},
overlaySubtext: {
fontSize: 14,
color: theme.palette.text.secondary,
},
terminal: {
width: "100vw",
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy