Skip to content

Commit

Permalink
fix(connections): add more accurate collective padding to time window
Browse files Browse the repository at this point in the history
  • Loading branch information
byhow authored and gary02 committed Aug 21, 2024
1 parent 5db714c commit 1a4114c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/common/utils/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export const connectionFromArray = <T>(
): Connection<T> => {
if (totalCount) {
const { after, before, first } = args // after and before should not appear together
const offset = before ? -cursorToIndex(before) : after ? cursorToIndex(after) + 1 : 0
const offset = before
? cursorToIndex(before) - (first ?? 0)
: after
? cursorToIndex(after) + 1
: 0

const edges = data.map((value, index) => ({
cursor: indexToCursor(index + offset),
Expand All @@ -79,8 +83,11 @@ export const connectionFromArray = <T>(
const beforeIndex = cursorToIndex(before)
hasPreviousPage = beforeIndex >= (first ? first : 0)
} else {
hasPreviousPage = first ? first - cursorToIndex(firstEdge.cursor) > 0 : cursorToIndex(firstEdge.cursor) > 0
hasPreviousPage = first
? first - cursorToIndex(firstEdge.cursor) > 0
: cursorToIndex(firstEdge.cursor) > 0
}
console.log(`first cursor is: `, cursorToIndex(firstEdge.cursor))

if (lastEdge) {
hasNextPage = cursorToIndex(lastEdge.cursor) + 1 < totalCount
Expand Down

0 comments on commit 1a4114c

Please sign in to comment.