diff options
Diffstat (limited to 'packages/bank-ui')
-rw-r--r-- | packages/bank-ui/src/hooks/account.ts | 11 | ||||
-rw-r--r-- | packages/bank-ui/src/hooks/regional.ts | 8 | ||||
-rw-r--r-- | packages/bank-ui/src/utils.ts | 6 |
3 files changed, 15 insertions, 10 deletions
diff --git a/packages/bank-ui/src/hooks/account.ts b/packages/bank-ui/src/hooks/account.ts index e1cd423de..43d43a3f2 100644 --- a/packages/bank-ui/src/hooks/account.ts +++ b/packages/bank-ui/src/hooks/account.ts @@ -22,12 +22,12 @@ import { WithdrawalOperationStatus, } from "@gnu-taler/taler-util"; import { useEffect, useState } from "preact/hooks"; -import { PAGE_SIZE } from "../utils.js"; import { useSessionState } from "./session.js"; // FIX default import https://github.com/microsoft/TypeScript/issues/49189 import _useSWR, { SWRHook, mutate } from "swr"; import { useBankCoreApiContext } from "@gnu-taler/web-util/browser"; +import { PAGINATED_LIST_REQUEST } from "../utils.js"; const useSWR = _useSWR as unknown as SWRHook; export interface InstanceTemplateFilter { @@ -184,7 +184,7 @@ export function usePublicAccounts( return await api.getPublicAccounts( { account }, { - limit: PAGE_SIZE, + limit: PAGINATED_LIST_REQUEST, offset: txid ? String(txid) : undefined, order: "asc", }, @@ -232,11 +232,12 @@ export function buildPaginatedResult<DataType, OffsetId>( setOffset: (o: OffsetId | undefined) => void, getId: (r: DataType) => OffsetId, ): PaginatedResult<DataType[]> { - const isLastPage = data.length <= PAGE_SIZE; + const isLastPage = data.length < PAGINATED_LIST_REQUEST; const isFirstPage = offset === undefined; const result = structuredClone(data); - if (result.length == PAGE_SIZE + 1) { + if (result.length == PAGINATED_LIST_REQUEST) { + //do now show the last element, used to know if this is the last page result.pop(); } return { @@ -280,7 +281,7 @@ export function useTransactions(account: string, initial?: number) { return await api.getTransactions( { username, token }, { - limit: PAGE_SIZE + 1, + limit: PAGINATED_LIST_REQUEST, offset: txid ? String(txid) : undefined, order: "dec", }, diff --git a/packages/bank-ui/src/hooks/regional.ts b/packages/bank-ui/src/hooks/regional.ts index 909bcfcec..e0c861a0f 100644 --- a/packages/bank-ui/src/hooks/regional.ts +++ b/packages/bank-ui/src/hooks/regional.ts @@ -14,7 +14,6 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { PAGE_SIZE } from "../utils.js"; import { useSessionState } from "./session.js"; import { @@ -36,6 +35,7 @@ import { useBankCoreApiContext } from "@gnu-taler/web-util/browser"; import { useState } from "preact/hooks"; import _useSWR, { SWRHook, mutate } from "swr"; import { buildPaginatedResult } from "./account.js"; +import { PAGINATED_LIST_REQUEST } from "../utils.js"; // FIX default import https://github.com/microsoft/TypeScript/issues/49189 const useSWR = _useSWR as unknown as SWRHook; @@ -232,14 +232,14 @@ export function useBusinessAccounts() { const [offset, setOffset] = useState<number | undefined>(); - function fetcher([token, offset]: [AccessToken, number]) { + function fetcher([token, aid]: [AccessToken, number]) { // FIXME: add account name filter return api.getAccounts( token, {}, { - limit: PAGE_SIZE + 1, - offset: String(offset), + limit: PAGINATED_LIST_REQUEST, + offset: aid ? String(aid) : undefined, order: "asc", }, ); diff --git a/packages/bank-ui/src/utils.ts b/packages/bank-ui/src/utils.ts index 305f13803..2cc502416 100644 --- a/packages/bank-ui/src/utils.ts +++ b/packages/bank-ui/src/utils.ts @@ -120,7 +120,11 @@ export enum CashoutStatus { PENDING = "pending", } -export const PAGE_SIZE = 5; + +export const PAGINATED_LIST_SIZE = 5; +// when doing paginated request, ask for one more +// and use it to know if there are more to request +export const PAGINATED_LIST_REQUEST = PAGINATED_LIST_SIZE + 1; type Translator = ReturnType<typeof useTranslationContext>["i18n"]; |