| 1 | import type { VcsListRefsResult } from "@t3tools/contracts"; |
| 2 | import * as Option from "effect/Option"; |
| 3 | import { AsyncResult } from "effect/reactivity"; |
| 4 | |
| 5 | const DEFAULT_NEXT_PAGE_DISTANCE_PX = 96; |
| 6 | |
| 7 | export function isPaginatedBranchesNextPagePending<E>( |
| 8 | results: ReadonlyArray<AsyncResult.AsyncResult<VcsListRefsResult, E>>, |
| 9 | ): boolean { |
| 10 | const lastResult = results.at(-1); |
| 11 | return ( |
| 12 | results.length > 1 && |
| 13 | lastResult?.waiting === true && |
| 14 | Option.isNone(AsyncResult.value(lastResult)) |
| 15 | ); |
| 16 | } |
| 17 | |
| 18 | export function shouldLoadNextBranchPageAfterScroll({ |
| 19 | previousScrollTop, |
| 20 | scrollTop, |
| 21 | scrollHeight, |
| 22 | clientHeight, |
| 23 | distanceThreshold = DEFAULT_NEXT_PAGE_DISTANCE_PX, |
| 24 | }: { |
| 25 | previousScrollTop: number | null; |
| 26 | scrollTop: number; |
| 27 | scrollHeight: number; |
| 28 | clientHeight: number; |
| 29 | distanceThreshold?: number; |
| 30 | }): boolean { |
| 31 | if (previousScrollTop === null || scrollTop <= previousScrollTop) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | return scrollHeight - scrollTop - clientHeight <= distanceThreshold; |
| 36 | } |