|
@@ -85,17 +85,19 @@ function useHistory() {
|
|
|
atEnd: false,
|
|
atEnd: false,
|
|
|
freeHistoryLimitHit: false,
|
|
freeHistoryLimitHit: false,
|
|
|
nextBeforeTimestamp: undefined,
|
|
nextBeforeTimestamp: undefined,
|
|
|
|
|
+ loadingState: 'loadingInitial',
|
|
|
})
|
|
})
|
|
|
const [labels, setLabels] = useState<HistoryContextValue['labels']>(null)
|
|
const [labels, setLabels] = useState<HistoryContextValue['labels']>(null)
|
|
|
const [labelsOnly, setLabelsOnly] = usePersistedState(
|
|
const [labelsOnly, setLabelsOnly] = usePersistedState(
|
|
|
`history.userPrefs.showOnlyLabels.${projectId}`,
|
|
`history.userPrefs.showOnlyLabels.${projectId}`,
|
|
|
false
|
|
false
|
|
|
)
|
|
)
|
|
|
- const [loadingState, setLoadingState] =
|
|
|
|
|
- useState<HistoryContextValue['loadingState']>('loadingInitial')
|
|
|
|
|
|
|
+ const [loadingFileDiffs, setLoadingFileDiffs] = useState(false)
|
|
|
const [error, setError] = useState<HistoryContextValue['error']>(null)
|
|
const [error, setError] = useState<HistoryContextValue['error']>(null)
|
|
|
|
|
|
|
|
const fetchNextBatchOfUpdates = useCallback(() => {
|
|
const fetchNextBatchOfUpdates = useCallback(() => {
|
|
|
|
|
+ const updatesLoadingState = updatesInfo.loadingState
|
|
|
|
|
+
|
|
|
const loadUpdates = (updatesData: Update[]) => {
|
|
const loadUpdates = (updatesData: Update[]) => {
|
|
|
const dateTimeNow = new Date()
|
|
const dateTimeNow = new Date()
|
|
|
const timestamp24hoursAgo = dateTimeNow.setDate(dateTimeNow.getDate() - 1)
|
|
const timestamp24hoursAgo = dateTimeNow.setDate(dateTimeNow.getDate() - 1)
|
|
@@ -140,7 +142,10 @@ function useHistory() {
|
|
|
|
|
|
|
|
if (
|
|
if (
|
|
|
updatesInfo.atEnd ||
|
|
updatesInfo.atEnd ||
|
|
|
- !(loadingState === 'loadingInitial' || loadingState === 'ready')
|
|
|
|
|
|
|
+ !(
|
|
|
|
|
+ updatesLoadingState === 'loadingInitial' ||
|
|
|
|
|
+ updatesLoadingState === 'ready'
|
|
|
|
|
+ )
|
|
|
) {
|
|
) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -150,9 +155,11 @@ function useHistory() {
|
|
|
)
|
|
)
|
|
|
const labelsPromise = labels == null ? fetchLabels(projectId) : null
|
|
const labelsPromise = labels == null ? fetchLabels(projectId) : null
|
|
|
|
|
|
|
|
- setLoadingState(
|
|
|
|
|
- loadingState === 'ready' ? 'loadingUpdates' : 'loadingInitial'
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ setUpdatesInfo({
|
|
|
|
|
+ ...updatesInfo,
|
|
|
|
|
+ loadingState:
|
|
|
|
|
+ updatesLoadingState === 'ready' ? 'loadingUpdates' : 'loadingInitial',
|
|
|
|
|
+ })
|
|
|
Promise.all([updatesPromise, labelsPromise])
|
|
Promise.all([updatesPromise, labelsPromise])
|
|
|
.then(([{ updates: updatesData, nextBeforeTimestamp }, labels]) => {
|
|
.then(([{ updates: updatesData, nextBeforeTimestamp }, labels]) => {
|
|
|
const lastUpdateToV = updatesData.length ? updatesData[0].toV : null
|
|
const lastUpdateToV = updatesData.length ? updatesData[0].toV : null
|
|
@@ -173,16 +180,14 @@ function useHistory() {
|
|
|
freeHistoryLimitHit,
|
|
freeHistoryLimitHit,
|
|
|
atEnd,
|
|
atEnd,
|
|
|
nextBeforeTimestamp,
|
|
nextBeforeTimestamp,
|
|
|
|
|
+ loadingState: 'ready',
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
.catch(error => {
|
|
.catch(error => {
|
|
|
setError(error)
|
|
setError(error)
|
|
|
- setUpdatesInfo({ ...updatesInfo, atEnd: true })
|
|
|
|
|
- })
|
|
|
|
|
- .finally(() => {
|
|
|
|
|
- setLoadingState('ready')
|
|
|
|
|
|
|
+ setUpdatesInfo({ ...updatesInfo, atEnd: true, loadingState: 'ready' })
|
|
|
})
|
|
})
|
|
|
- }, [loadingState, labels, projectId, userHasFullFeature, updatesInfo])
|
|
|
|
|
|
|
+ }, [updatesInfo, projectId, labels, userHasFullFeature])
|
|
|
|
|
|
|
|
const resetSelection = useCallback(() => {
|
|
const resetSelection = useCallback(() => {
|
|
|
setSelection(selectionInitialState)
|
|
setSelection(selectionInitialState)
|
|
@@ -203,12 +208,12 @@ function useHistory() {
|
|
|
|
|
|
|
|
// Load files when the update selection changes
|
|
// Load files when the update selection changes
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- if (!updateRange || loadingState !== 'ready' || !filesEmpty) {
|
|
|
|
|
|
|
+ if (!updateRange || updatesInfo.loadingState !== 'ready' || !filesEmpty) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
const { fromV, toV } = updateRange
|
|
const { fromV, toV } = updateRange
|
|
|
|
|
|
|
|
- setLoadingState('loadingFileDiffs')
|
|
|
|
|
|
|
+ setLoadingFileDiffs(true)
|
|
|
|
|
|
|
|
diffFiles(projectId, fromV, toV)
|
|
diffFiles(projectId, fromV, toV)
|
|
|
.then(({ diff: files }) => {
|
|
.then(({ diff: files }) => {
|
|
@@ -236,7 +241,7 @@ function useHistory() {
|
|
|
setError(error)
|
|
setError(error)
|
|
|
})
|
|
})
|
|
|
.finally(() => {
|
|
.finally(() => {
|
|
|
- setLoadingState('ready')
|
|
|
|
|
|
|
+ setLoadingFileDiffs(false)
|
|
|
})
|
|
})
|
|
|
}, [
|
|
}, [
|
|
|
updateRange,
|
|
updateRange,
|
|
@@ -244,7 +249,7 @@ function useHistory() {
|
|
|
updates,
|
|
updates,
|
|
|
comparing,
|
|
comparing,
|
|
|
setError,
|
|
setError,
|
|
|
- loadingState,
|
|
|
|
|
|
|
+ updatesInfo.loadingState,
|
|
|
filesEmpty,
|
|
filesEmpty,
|
|
|
])
|
|
])
|
|
|
|
|
|
|
@@ -268,8 +273,8 @@ function useHistory() {
|
|
|
() => ({
|
|
() => ({
|
|
|
error,
|
|
error,
|
|
|
setError,
|
|
setError,
|
|
|
- loadingState,
|
|
|
|
|
- setLoadingState,
|
|
|
|
|
|
|
+ loadingFileDiffs,
|
|
|
|
|
+ setLoadingFileDiffs,
|
|
|
updatesInfo,
|
|
updatesInfo,
|
|
|
setUpdatesInfo,
|
|
setUpdatesInfo,
|
|
|
labels,
|
|
labels,
|
|
@@ -287,8 +292,8 @@ function useHistory() {
|
|
|
[
|
|
[
|
|
|
error,
|
|
error,
|
|
|
setError,
|
|
setError,
|
|
|
- loadingState,
|
|
|
|
|
- setLoadingState,
|
|
|
|
|
|
|
+ loadingFileDiffs,
|
|
|
|
|
+ setLoadingFileDiffs,
|
|
|
updatesInfo,
|
|
updatesInfo,
|
|
|
setUpdatesInfo,
|
|
setUpdatesInfo,
|
|
|
labels,
|
|
labels,
|