diff options
Diffstat (limited to 'packages/demobank-ui/src/hooks')
-rw-r--r-- | packages/demobank-ui/src/hooks/access.ts | 23 | ||||
-rw-r--r-- | packages/demobank-ui/src/hooks/backend.ts | 18 |
2 files changed, 25 insertions, 16 deletions
diff --git a/packages/demobank-ui/src/hooks/access.ts b/packages/demobank-ui/src/hooks/access.ts index 2f6848af8..20fd64bfa 100644 --- a/packages/demobank-ui/src/hooks/access.ts +++ b/packages/demobank-ui/src/hooks/access.ts @@ -255,7 +255,7 @@ export function useTransactionDetails( } interface PaginationFilter { - page: number; + // page: number; } export function usePublicAccounts( @@ -275,7 +275,7 @@ export function usePublicAccounts( } = useSWR< HttpResponseOk<SandboxBackend.CoreBank.PublicAccountsResponse>, RequestError<SandboxBackend.SandboxError> - >([`public-accounts`, args?.page, PAGE_SIZE], paginatedFetcher); + >([`public-accounts`, page, PAGE_SIZE], paginatedFetcher); const [lastAfter, setLastAfter] = useState< HttpResponse< @@ -334,7 +334,7 @@ export function useTransactions( > { const { paginatedFetcher } = useAuthenticatedBackend(); - const [page, setPage] = useState(1); + const [start, setStart] = useState<string>(); const { data: afterData, @@ -344,7 +344,7 @@ export function useTransactions( HttpResponseOk<SandboxBackend.CoreBank.BankAccountTransactionsResponse>, RequestError<SandboxBackend.SandboxError> >( - [`accounts/${account}/transactions`, args?.page, PAGE_SIZE], + [`accounts/${account}/transactions`, start, PAGE_SIZE], paginatedFetcher, { refreshInterval: 0, refreshWhenHidden: false, @@ -374,19 +374,24 @@ export function useTransactions( // if the query returns less that we ask, then we have reach the end or beginning const isReachingEnd = afterData && afterData.data.transactions.length < PAGE_SIZE; - const isReachingStart = false; + const isReachingStart = start == undefined; const pagination = { isReachingEnd, isReachingStart, loadMore: () => { if (!afterData || isReachingEnd) return; - if (afterData.data.transactions.length < MAX_RESULT_SIZE) { - setPage(page + 1); - } + // if (afterData.data.transactions.length < MAX_RESULT_SIZE) { + // console.log("load more", page) + const l = afterData.data.transactions[afterData.data.transactions.length-1] + setStart(String(l.row_id)); + // } }, loadMorePrev: () => { - null; + if (!afterData || isReachingStart) return; + // if (afterData.data.transactions.length < MAX_RESULT_SIZE) { + setStart(undefined) + // } }, }; diff --git a/packages/demobank-ui/src/hooks/backend.ts b/packages/demobank-ui/src/hooks/backend.ts index e6a3a1c0c..3d5bfa360 100644 --- a/packages/demobank-ui/src/hooks/backend.ts +++ b/packages/demobank-ui/src/hooks/backend.ts @@ -159,7 +159,7 @@ interface useBackendType { fetcher: <T>(endpoint: string) => Promise<HttpResponseOk<T>>; multiFetcher: <T>(endpoint: string[][]) => Promise<HttpResponseOk<T>[]>; paginatedFetcher: <T>( - args: [string, number, number], + args: [string, string | undefined, number], ) => Promise<HttpResponseOk<T>>; sandboxAccountsFetcher: <T>( args: [string, number, number, string], @@ -188,13 +188,15 @@ export function usePublicBackend(): useBackendType { [baseUrl], ); const paginatedFetcher = useCallback( - function fetcherImpl<T>([endpoint, page, size]: [ + function fetcherImpl<T>([endpoint, start, size]: [ string, - number, + string | undefined, number, ]): Promise<HttpResponseOk<T>> { + const delta = -1 * size //descending order + const params = start ? { delta, start } : {delta} return requestHandler<T>(baseUrl, endpoint, { - params: { page: page || 1, size }, + params, }); }, [baseUrl], @@ -280,14 +282,16 @@ export function useAuthenticatedBackend(): useBackendType { [baseUrl, creds], ); const paginatedFetcher = useCallback( - function fetcherImpl<T>([endpoint, page = 1, size]: [ + function fetcherImpl<T>([endpoint, start, size]: [ string, - number, + string | undefined, number, ]): Promise<HttpResponseOk<T>> { + const delta = -1 * size //descending order + const params = start ? { delta, start } : {delta} return requestHandler<T>(baseUrl, endpoint, { token: creds, - params: { delta: size, start: size * page }, + params, }); }, [baseUrl, creds], |