This repository was archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add loading indicator text when loading large code files #45174
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className="d-flex mt-3 justify-content-center"> | ||
{afterOneSec ? ( | ||
<div className="d-flex flex-column align-items-center"> | ||
<LoadingSpinner /> | ||
<div className="text-muted mt-2"> | ||
{afterNineSec ? ( | ||
<> | ||
It’s taking much longer than expected to load this file. Try{' '} | ||
<Link to={location.pathname} onClick={reload}> | ||
reloading the page | ||
</Link> | ||
. | ||
</> | ||
) : afterSixSec ? ( | ||
'Loading a whole lot of bits and bytes here...' | ||
) : afterThreeSec ? ( | ||
'Loading a large file...' | ||
) : ( | ||
'' | ||
)} | ||
</div> | ||
</div> | ||
) : null} | ||
</div> | ||
) | ||
} | ||
|
||
function reload(event: React.MouseEvent<HTMLAnchorElement>): void { | ||
window.location.reload() | ||
event.preventDefault() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.