Skip to content

Commit

Permalink
fix(dashboard): NFT IDs pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Jan 16, 2024
1 parent 0578575 commit 168bcf1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
const loadedLaterNfts: Record<string, GeneralNft[]> = {}
let isLoading = false
let currentCursor: string | null | undefined = null
let currentCursors: Record<string, string | null | undefined> = {}
$: {
nonFungibleResources.then((data) => {
data.forEach((resource) => {
currentCursors[resource.address] = null
})
})
}
$: data = Promise.all([stateVersion, account, nfts])
Expand All @@ -39,18 +47,19 @@
const fetchMore = (data: GetNonFungibleIdsPageWithDataRequest) => {
if (
isLoading ||
currentCursor === undefined ||
(data.cursor === undefined && currentCursor === null)
currentCursors[data.resourceAddress] === undefined ||
(data.cursor === undefined &&
currentCursors[data.resourceAddress] === null)
) {
return
}
isLoading = true
getNonFungiblesIdsPageWithData({
...data,
cursor: currentCursor || data.cursor
cursor: currentCursors[data.resourceAddress] || data.cursor
}).then(([response, nftDataResponse]) => {
currentCursor = response.next_cursor
currentCursors[data.resourceAddress] = response.next_cursor
if (!loadedLaterNfts[data.resourceAddress]) {
loadedLaterNfts[data.resourceAddress] = []
}
Expand Down Expand Up @@ -144,6 +153,7 @@
</div>

<InfiniteScroll
middlePageMode={true}
on:thresholdReached={() => {
fetchMore({
stateVersion,
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/src/components/infinite-scroll/InfiniteScroll.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { onDestroy, createEventDispatcher, onMount } from 'svelte'
export let threshold = 5
export let middlePageMode = false
const dispatch = createEventDispatcher()
let component: HTMLElement
Expand Down Expand Up @@ -65,6 +66,15 @@
})
const onScroll = (e: any) => {
if (middlePageMode) {
if (
component.parentElement?.clientHeight &&
component.parentElement?.clientHeight - e.target.scrollTop < 2500
) {
dispatch('thresholdReached')
}
}
const offset =
e.target.scrollHeight - e.target.clientHeight - e.target.scrollTop
Expand Down

0 comments on commit 168bcf1

Please sign in to comment.