-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ITO lazy load history list (#3524)
- Loading branch information
1 parent
07dbc5e
commit 119ee53
Showing
8 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
packages/maskbook/src/plugins/ITO/hooks/useAllPoolsAsSeller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import { useAsyncRetry } from 'react-use' | ||
import { PluginITO_RPC } from '../messages' | ||
import type { PoolSubgraph } from '../types' | ||
import { useRef } from 'react' | ||
|
||
export function useAllPoolsAsSeller(address: string) { | ||
export function useAllPoolsAsSeller(address: string, page: number) { | ||
const allPoolsRef = useRef<PoolSubgraph[]>([]) | ||
return useAsyncRetry(async () => { | ||
const pools = await PluginITO_RPC.getAllPoolsAsSeller(address) | ||
return pools.reverse() | ||
}, [address]) | ||
const pools = await PluginITO_RPC.getAllPoolsAsSeller(address, page) | ||
allPoolsRef.current = allPoolsRef.current.concat(pools) | ||
return allPoolsRef.current | ||
}, [address, page]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useValueRef' | ||
export * from './useObservableMapSet' | ||
export * from './useMenu' | ||
export * from './useScrollBottomEvent' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useLayoutEffect, RefObject, useCallback } from 'react' | ||
import { debounce } from 'lodash-es' | ||
|
||
export function useScrollBottomEvent(ref: RefObject<HTMLDivElement>, cb: () => void) { | ||
const onScroll = useCallback( | ||
debounce(function (_ev: Event) { | ||
// ev.currentTarget is always null when applies debounce(). | ||
const ev = _ev as Event & { path: HTMLDivElement[] } | ||
const element = ev.path[0] | ||
// On some device, there's a slight deviation between `scrollHeight` and `offsetHeight + scrollTop` | ||
const isBottomArrived = Math.abs(element.scrollHeight - element.offsetHeight - element.scrollTop) < 2 | ||
if (isBottomArrived) cb() | ||
}, 300), | ||
[cb], | ||
) | ||
|
||
useLayoutEffect(() => { | ||
if (!ref.current) return | ||
ref.current.addEventListener('scroll', onScroll) | ||
// useLayoutEffect() to remove the listener before changes painted on screen. | ||
return () => ref.current!.removeEventListener('scroll', onScroll) | ||
}, [onScroll]) | ||
} |