diff --git a/client/web/src/repo/blob/BlobLoadingSpinner.tsx b/client/web/src/repo/blob/BlobLoadingSpinner.tsx new file mode 100644 index 000000000000..cbbc173a2b8e --- /dev/null +++ b/client/web/src/repo/blob/BlobLoadingSpinner.tsx @@ -0,0 +1,63 @@ +import { useEffect, useState } from 'react' + +import { useLocation } from 'react-router' + +import { Link, LoadingSpinner } from '@sourcegraph/wildcard' + +export function BlobLoadingSpinner(): JSX.Element { + const [afterOneSec, setAfterOneSec] = useState(false) + const [afterThreeSec, setAfterThreeSec] = useState(false) + const [afterSixSec, setAfterSixSec] = useState(false) + const [afterNineSec, setAfterNineSec] = useState(false) + + useEffect(() => { + const timeout = setTimeout(() => setAfterOneSec(true), 1000) + return () => clearTimeout(timeout) + }, []) + useEffect(() => { + const timeout = setTimeout(() => setAfterThreeSec(true), 3000) + return () => clearTimeout(timeout) + }, []) + useEffect(() => { + const timeout = setTimeout(() => setAfterSixSec(true), 6000) + return () => clearTimeout(timeout) + }, []) + useEffect(() => { + const timeout = setTimeout(() => setAfterNineSec(true), 9000) + return () => clearTimeout(timeout) + }, []) + + const location = useLocation() + + return ( +
+ {afterOneSec ? ( +
+ +
+ {afterNineSec ? ( + <> + It’s taking much longer than expected to load this file. Try{' '} + + reloading the page + + . + + ) : afterSixSec ? ( + 'Loading a whole lot of bits and bytes here...' + ) : afterThreeSec ? ( + 'Loading a large file...' + ) : ( + '' + )} +
+
+ ) : null} +
+ ) +} + +function reload(event: React.MouseEvent): void { + window.location.reload() + event.preventDefault() +} diff --git a/client/web/src/repo/blob/BlobPage.tsx b/client/web/src/repo/blob/BlobPage.tsx index 5c5769ac1ab8..8b73c2ec594f 100644 --- a/client/web/src/repo/blob/BlobPage.tsx +++ b/client/web/src/repo/blob/BlobPage.tsx @@ -66,6 +66,7 @@ import { ToggleRenderedFileMode } from './actions/ToggleRenderedFileMode' import { getModeFromURL } from './actions/utils' import { fetchBlob, fetchStencil } from './backend' import { Blob, BlobInfo } from './Blob' +import { BlobLoadingSpinner } from './BlobLoadingSpinner' import { Blob as CodeMirrorBlob } from './CodeMirrorBlob' import { GoToRawAction } from './GoToRawAction' import { BlobPanel } from './panel/BlobPanel' @@ -441,11 +442,7 @@ export const BlobPage: React.FunctionComponent {alwaysRender} - {!enableLazyBlobSyntaxHighlighting && ( -
- -
- )} + {!enableLazyBlobSyntaxHighlighting && } ) }