Skip to content

Commit

Permalink
feat(structure): load a minimum of 16 parent entries in history
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Nov 7, 2024
1 parent 4d2ac88 commit eaff9b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export class TimelineController {
return this._revTime && typeof this._revTime === 'object' ? this._revTime : null
}

get isLoading(): boolean {
return this._isRunning
}

get realRevChunk(): Chunk {
return this.revTime || this.timeline.lastChunk()
}
Expand Down Expand Up @@ -258,6 +262,7 @@ export class TimelineController {
!this._isSuspended

if (!shouldFetchMore) {
this._isRunning = false
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ export function useTimelineStore({
findRangeForSince: (chunk: Chunk) => controller.findRangeForNewSince(chunk),
loadMore: () => {
controller.setLoadMore(true)
timelineStateRef.current.isLoading = true
},
getSnapshot: () => timelineStateRef.current,
subscribe: (callback: () => void) => {
Expand All @@ -217,7 +216,7 @@ export function useTimelineStore({
return {
chunks,
diff: innerController.sinceTime ? innerController.currentObjectDiff() : null,
isLoading: false,
isLoading: innerController.isLoading,
isPristine: timelineReady ? chunks.length === 0 && hasMoreChunks === false : null,
hasMoreChunks: !innerController.timeline.reachedEarliestEntry,
lastNonDeletedRevId: lastNonDeletedChunk?.[0]?.id,
Expand Down
10 changes: 10 additions & 0 deletions packages/sanity/src/structure/panes/document/timeline/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export const Timeline = ({
})
}, [chunksWithMetadata, expandedParents])

useEffect(() => {
// This effect ensures that we load more chunks if the list is not long enough.
// This could happen if a parent chunk has multiple drafts, so you could end with a list of 50 transactions but only
// 1 parent chunk, the publish, which squashed all the changes.
// In that case, users will see the loading block at the bottom, but nothing will really be happening. Because they haven't reach the end of the list.
if (filteredChunks.length < 16 && hasMoreChunks) {
onLoadMore()
}
}, [filteredChunks, hasMoreChunks, onLoadMore])

const handleExpandParent = useCallback(
(parentId: string) => () =>
setExpandedParents((prev) => {
Expand Down

0 comments on commit eaff9b0

Please sign in to comment.