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 2e16919
Show file tree
Hide file tree
Showing 3 changed files with 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export const Timeline = ({
})
}, [chunksWithMetadata, expandedParents])

useEffect(() => {
if (filteredChunks.length < 16 && hasMoreChunks) {
onLoadMore()
}
}, [filteredChunks, hasMoreChunks, onLoadMore])

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

0 comments on commit 2e16919

Please sign in to comment.