Skip to content

Commit 1a4114c

Browse files
byhowgary02
authored andcommitted
fix(connections): add more accurate collective padding to time window
1 parent 5db714c commit 1a4114c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/common/utils/connections.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ export const connectionFromArray = <T>(
5959
): Connection<T> => {
6060
if (totalCount) {
6161
const { after, before, first } = args // after and before should not appear together
62-
const offset = before ? -cursorToIndex(before) : after ? cursorToIndex(after) + 1 : 0
62+
const offset = before
63+
? cursorToIndex(before) - (first ?? 0)
64+
: after
65+
? cursorToIndex(after) + 1
66+
: 0
6367

6468
const edges = data.map((value, index) => ({
6569
cursor: indexToCursor(index + offset),
@@ -79,8 +83,11 @@ export const connectionFromArray = <T>(
7983
const beforeIndex = cursorToIndex(before)
8084
hasPreviousPage = beforeIndex >= (first ? first : 0)
8185
} else {
82-
hasPreviousPage = first ? first - cursorToIndex(firstEdge.cursor) > 0 : cursorToIndex(firstEdge.cursor) > 0
86+
hasPreviousPage = first
87+
? first - cursorToIndex(firstEdge.cursor) > 0
88+
: cursorToIndex(firstEdge.cursor) > 0
8389
}
90+
console.log(`first cursor is: `, cursorToIndex(firstEdge.cursor))
8491

8592
if (lastEdge) {
8693
hasNextPage = cursorToIndex(lastEdge.cursor) + 1 < totalCount

0 commit comments

Comments
 (0)