From 9b9d294f98be19cb83e697484327335d4f73e7ef Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Sun, 16 Jul 2023 17:45:16 -0500 Subject: [PATCH] feat(connection-test): [closes #127] Explain tracker connection problems (#130) * feat(connection-test): [closes #127] explain tracker connection problems --- .../Shell/ConnectionTestResults.tsx | 14 +++- .../Shell/ServerConnectionFailureDialog.tsx | 65 +++++++++++++++++++ src/components/Shell/Shell.tsx | 10 +++ src/contexts/ShellContext.ts | 4 ++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/components/Shell/ServerConnectionFailureDialog.tsx diff --git a/src/components/Shell/ConnectionTestResults.tsx b/src/components/Shell/ConnectionTestResults.tsx index 7f4c83c..c3dab4a 100644 --- a/src/components/Shell/ConnectionTestResults.tsx +++ b/src/components/Shell/ConnectionTestResults.tsx @@ -1,3 +1,4 @@ +import { useContext } from 'react' import CircularProgress from '@mui/material/CircularProgress' import Tooltip from '@mui/material/Tooltip' import Typography from '@mui/material/Typography' @@ -6,6 +7,7 @@ import { Box } from '@mui/system' import ReportIcon from '@mui/icons-material/Report' import { TrackerConnection } from 'services/ConnectionTest/ConnectionTest' +import { ShellContext } from 'contexts/ShellContext' import { ConnectionTestResults as IConnectionTestResults } from './useConnectionTest' @@ -15,9 +17,19 @@ interface ConnectionTestResultsProps { export const ConnectionTestResults = ({ connectionTestResults: { hasHost, hasRelay, trackerConnection }, }: ConnectionTestResultsProps) => { + const { setIsServerConnectionFailureDialogOpen } = useContext(ShellContext) + + const handleServerConnectionFailedMessageClick = () => { + setIsServerConnectionFailureDialogOpen(true) + } + if (trackerConnection === TrackerConnection.FAILED) { return ( - + diff --git a/src/components/Shell/ServerConnectionFailureDialog.tsx b/src/components/Shell/ServerConnectionFailureDialog.tsx new file mode 100644 index 0000000..3e1aa2c --- /dev/null +++ b/src/components/Shell/ServerConnectionFailureDialog.tsx @@ -0,0 +1,65 @@ +import { useContext } from 'react' +import useTheme from '@mui/material/styles/useTheme' +import Typography from '@mui/material/Typography' +import Box from '@mui/material/Box' +import Button from '@mui/material/Button' +import Dialog from '@mui/material/Dialog' +import DialogActions from '@mui/material/DialogActions' +import DialogContent from '@mui/material/DialogContent' +import DialogContentText from '@mui/material/DialogContentText' +import DialogTitle from '@mui/material/DialogTitle' +import ReportIcon from '@mui/icons-material/Report' + +import { ShellContext } from 'contexts/ShellContext' + +export const ServerConnectionFailureDialog = () => { + const theme = useTheme() + const { + isServerConnectionFailureDialogOpen, + setIsServerConnectionFailureDialogOpen, + } = useContext(ShellContext) + + const handleDialogClose = () => { + setIsServerConnectionFailureDialogOpen(false) + } + + return ( + + + + ({ + color: theme.palette.error.main, + mr: theme.spacing(1), + })} + /> + Server connection failed + + + + + A pairing server could not be found. Make sure you are connected to + the internet. If you still can't connect, try: + + +
  • Refreshing the page
  • +
  • Disabling any adblockers
  • +
  • Connecting to a different network
  • +
    +
    + + + +
    + ) +} diff --git a/src/components/Shell/Shell.tsx b/src/components/Shell/Shell.tsx index 411270f..2833196 100644 --- a/src/components/Shell/Shell.tsx +++ b/src/components/Shell/Shell.tsx @@ -30,6 +30,7 @@ import { PeerList } from './PeerList' import { QRCodeDialog } from './QRCodeDialog' import { RoomShareDialog } from './RoomShareDialog' import { useConnectionTest } from './useConnectionTest' +import { ServerConnectionFailureDialog } from './ServerConnectionFailureDialog' export interface ShellProps extends PropsWithChildren { userPeerId: string @@ -68,6 +69,10 @@ export const Shell = ({ appNeedsUpdate, children, userPeerId }: ShellProps) => { const [password, setPassword] = useState(undefined) const [isPeerListOpen, setIsPeerListOpen] = useState(defaultSidebarsOpen) const [peerList, setPeerList] = useState([]) // except self + const [ + isServerConnectionFailureDialogOpen, + setIsServerConnectionFailureDialogOpen, + ] = useState(false) const [peerConnectionTypes, setPeerConnectionTypes] = useState< Record >({}) @@ -109,6 +114,8 @@ export const Shell = ({ appNeedsUpdate, children, userPeerId }: ShellProps) => { setIsPeerListOpen, peerList, setPeerList, + isServerConnectionFailureDialogOpen, + setIsServerConnectionFailureDialogOpen, peerConnectionTypes, setPeerConnectionTypes, audioState, @@ -131,6 +138,8 @@ export const Shell = ({ appNeedsUpdate, children, userPeerId }: ShellProps) => { password, setPassword, peerList, + isServerConnectionFailureDialogOpen, + setIsServerConnectionFailureDialogOpen, peerConnectionTypes, tabHasFocus, showRoomControls, @@ -346,6 +355,7 @@ export const Shell = ({ appNeedsUpdate, children, userPeerId }: ShellProps) => { showAlert={showAlert} copyToClipboard={copyToClipboard} /> +
    diff --git a/src/contexts/ShellContext.ts b/src/contexts/ShellContext.ts index 16704e6..aa2e526 100644 --- a/src/contexts/ShellContext.ts +++ b/src/contexts/ShellContext.ts @@ -20,6 +20,8 @@ interface ShellContextProps { setIsPeerListOpen: Dispatch> peerList: Peer[] setPeerList: Dispatch> + isServerConnectionFailureDialogOpen: boolean + setIsServerConnectionFailureDialogOpen: Dispatch> peerConnectionTypes: Record setPeerConnectionTypes: Dispatch< SetStateAction> @@ -51,6 +53,8 @@ export const ShellContext = createContext({ setIsPeerListOpen: () => {}, peerList: [], setPeerList: () => {}, + isServerConnectionFailureDialogOpen: false, + setIsServerConnectionFailureDialogOpen: () => {}, peerConnectionTypes: {}, setPeerConnectionTypes: () => {}, audioState: AudioState.STOPPED,