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>
{showOwnerPaywall ? <OwnerPaywallPrompt /> : null}
{showNonOwnerPaywall ? <NonOwnerPaywallPrompt /> : null}
{loadingState === 'ready' ? null : <LoadingSpinner />}
{loadingState === 'loadingInitial' ||
loadingState === 'loadingUpdates' ? (
<LoadingSpinner />
) : null}
</div>
)
}

View file

@ -11,14 +11,15 @@ import ErrorMessage from '../error-message'
function DiffView() {
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 { updateRange, selectedFile } = selection
useEffect(() => {
if (!updateRange || !selectedFile?.pathname) {
if (!updateRange || !selectedFile?.pathname || loadingFileDiffs) {
return
}
@ -44,7 +45,7 @@ function DiffView() {
setDiff(diff)
})
.catch(console.error)
}, [projectId, runAsync, updateRange, selectedFile])
}, [projectId, runAsync, updateRange, selectedFile, loadingFileDiffs])
return (
<div className="doc-panel">
@ -56,7 +57,7 @@ function DiffView() {
<Toolbar diff={diff} selection={selection} />
</div>
<div className="doc-container">
<Main diff={diff} isLoading={isLoading} />
<Main diff={diff} isLoading={isLoading || loadingFileDiffs} />
</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(
fetchUpdates(projectId, updatesInfo.nextBeforeTimestamp)
@ -193,11 +198,13 @@ function useHistory() {
// Load files when the update selection changes
useEffect(() => {
if (!updateRange || !filesEmpty) {
if (!updateRange || loadingState !== 'ready' || !filesEmpty) {
return
}
const { fromV, toV } = updateRange
setLoadingState('loadingFileDiffs')
diffFiles(projectId, fromV, toV)
.then(({ diff: files }) => {
const selectedFile = autoSelectFile(
@ -223,7 +230,18 @@ function useHistory() {
.catch(error => {
setError(error)
})
}, [updateRange, projectId, updates, comparing, setError, filesEmpty])
.finally(() => {
setLoadingState('ready')
})
}, [
updateRange,
projectId,
updates,
comparing,
setError,
loadingState,
filesEmpty,
])
useEffect(() => {
// 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 =
| 'loadingInitial'
| 'loadingUpdates'
| 'loadingFileDiffs'
| 'restoringFile'
| 'ready'