Skip to content

Commit ee25874

Browse files
authored
Fix pagination and cursor navigation issues (#45)
* fix(browse): move cursor with viewport on page up/down Previously page up/down only scrolled the viewport while the cursor stayed in place, causing it to drift off screen. * fix(browse): fix load more pagination by excluding missing docs from offset When using DocumentRefs() to find all refs in a collection, it returns all document references including those on subsequent pages. These were being added as "missing" items (docs with no data). The docCount was including these missing items, inflating the offset used for pagination. When "load more" was triggered, the inflated offset would skip past all remaining documents, causing the query to return zero results. The sentinel would disappear but no new items appeared, making it seem like nothing happened. Fix by excluding isMissing items from the docCount calculation so the offset only reflects documents from the actual query results. --------- Co-authored-by: Gustavo Hoirisch <355877+gugahoi@users.noreply.github.com>
1 parent f24e6e8 commit ee25874

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

pkg/cmd/browse/firestore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,13 @@ func fetchColumnData(client *firestore.Client, path string, isDoc bool, columnIn
391391
}
392392
}
393393

394-
// Count documents in sections
394+
// Count queried documents (exclude missing refs and sentinel — docCount
395+
// is used as the Firestore query Offset for pagination)
395396
totalDocs := 0
396397
for _, s := range sections {
397398
if s.title == "Documents" {
398399
for _, item := range s.items {
399-
if item.path != "__load_more__" {
400+
if item.path != "__load_more__" && !item.isMissing {
400401
totalDocs++
401402
}
402403
}

pkg/cmd/browse/navigation.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ func (m *Model) scrollDown() {
319319
}
320320

321321
col.scrollOffset += pageSize
322+
323+
totalItems := m.getAllItemsCount(*col)
324+
col.cursor += pageSize
325+
if col.cursor >= totalItems {
326+
col.cursor = totalItems - 1
327+
}
322328
}
323329

324330
// scrollUp scrolls the active column up by half a page
@@ -339,6 +345,11 @@ func (m *Model) scrollUp() {
339345
if col.scrollOffset < 0 {
340346
col.scrollOffset = 0
341347
}
348+
349+
col.cursor -= pageSize
350+
if col.cursor < 0 {
351+
col.cursor = 0
352+
}
342353
}
343354

344355
// addColumn adds a new column to the right

0 commit comments

Comments
 (0)