Merge pull request #12873 from overleaf/td-history-loading-improvements

History migration: Improve loading logic and display for loading file diffs

GitOrigin-RevId: 9d20c4632e6a804cb21e6fffd52faa88bc03f01a
This commit is contained in:
Tim Down 2023-05-04 10:57:38 +01:00 committed by Copybot
parent 95646a1bd5
commit 27457133e4
4 changed files with 31 additions and 8 deletions

View file

@ -92,7 +92,10 @@ function AllHistoryList() {
</div> </div>
{showOwnerPaywall ? <OwnerPaywallPrompt /> : null} {showOwnerPaywall ? <OwnerPaywallPrompt /> : null}
{showNonOwnerPaywall ? <NonOwnerPaywallPrompt /> : null} {showNonOwnerPaywall ? <NonOwnerPaywallPrompt /> : null}
{loadingState === 'ready' ? null : <LoadingSpinner />} {loadingState === 'loadingInitial' ||
loadingState === 'loadingUpdates' ? (
<LoadingSpinner />
) : null}
</div> </div>
) )
} }

View file

@ -11,14 +11,15 @@ import ErrorMessage from '../error-message'
function DiffView() { function DiffView() {
const [diff, setDiff] = useState<Nullable<Diff>>(null) const [diff, setDiff] = useState<Nullable<Diff>>(null)
const { selection, projectId } = useHistoryContext() const { selection, projectId, loadingState } = useHistoryContext()
const loadingFileDiffs = loadingState === 'loadingFileDiffs'
const { isLoading, runAsync, error } = useAsync<DocDiffResponse>() const { isLoading, runAsync, error } = useAsync<DocDiffResponse>()
const { updateRange, selectedFile } = selection const { updateRange, selectedFile } = selection
useEffect(() => { useEffect(() => {
if (!updateRange || !selectedFile?.pathname) { if (!updateRange || !selectedFile?.pathname || loadingFileDiffs) {
return return
} }
@ -44,7 +45,7 @@ function DiffView() {
setDiff(diff) setDiff(diff)
}) })
.catch(console.error) .catch(console.error)
}, [projectId, runAsync, updateRange, selectedFile]) }, [projectId, runAsync, updateRange, selectedFile, loadingFileDiffs])
return ( return (
<div className="doc-panel"> <div className="doc-panel">
@ -56,7 +57,7 @@ function DiffView() {
<Toolbar diff={diff} selection={selection} /> <Toolbar diff={diff} selection={selection} />
</div> </div>
<div className="doc-container"> <div className="doc-container">
<Main diff={diff} isLoading={isLoading} /> <Main diff={diff} isLoading={isLoading || loadingFileDiffs} />
</div> </div>
</> </>
)} )}

View file

@ -133,7 +133,12 @@ function useHistory() {
} }
} }
if (updatesInfo.atEnd || loadingState === 'loadingUpdates') return if (
updatesInfo.atEnd ||
!(loadingState === 'loadingInitial' || loadingState === 'ready')
) {
return
}
const updatesPromise = limitUpdates( const updatesPromise = limitUpdates(
fetchUpdates(projectId, updatesInfo.nextBeforeTimestamp) fetchUpdates(projectId, updatesInfo.nextBeforeTimestamp)
@ -193,11 +198,13 @@ function useHistory() {
// Load files when the update selection changes // Load files when the update selection changes
useEffect(() => { useEffect(() => {
if (!updateRange || !filesEmpty) { if (!updateRange || loadingState !== 'ready' || !filesEmpty) {
return return
} }
const { fromV, toV } = updateRange const { fromV, toV } = updateRange
setLoadingState('loadingFileDiffs')
diffFiles(projectId, fromV, toV) diffFiles(projectId, fromV, toV)
.then(({ diff: files }) => { .then(({ diff: files }) => {
const selectedFile = autoSelectFile( const selectedFile = autoSelectFile(
@ -223,7 +230,18 @@ function useHistory() {
.catch(error => { .catch(error => {
setError(error) setError(error)
}) })
}, [updateRange, projectId, updates, comparing, setError, filesEmpty]) .finally(() => {
setLoadingState('ready')
})
}, [
updateRange,
projectId,
updates,
comparing,
setError,
loadingState,
filesEmpty,
])
useEffect(() => { useEffect(() => {
// Set update range if there isn't one and updates have loaded // Set update range if there isn't one and updates have loaded

View file

@ -6,6 +6,7 @@ import { Selection } from '../../services/types/selection'
type LoadingState = type LoadingState =
| 'loadingInitial' | 'loadingInitial'
| 'loadingUpdates' | 'loadingUpdates'
| 'loadingFileDiffs'
| 'restoringFile' | 'restoringFile'
| 'ready' | 'ready'