fix: fix empty rows on empty collateral list (#2312)

* fix: fix empty rows on empty collateral list

* fix: fix empty rows on empty collateral list

* fix: fix empty rows on empty collateral list
This commit is contained in:
macqbat 2022-12-05 11:05:31 +01:00 committed by GitHub
parent 5531566e2f
commit aafa3d7256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 6 deletions

View File

@ -1,4 +1,5 @@
/* eslint-disable */
process.env.TZ = 'UTC';
export default {
displayName: 'explorer',
preset: '../../jest.preset.js',

View File

@ -43,7 +43,7 @@ export const AccountManager = ({
const rowsThisBlock = dataRef.current
? dataRef.current.slice(startRow, endRow)
: [];
const lastRow = dataRef.current?.length ?? -1;
const lastRow = dataRef.current?.length ?? undefined;
successCallback(rowsThisBlock, lastRow);
},
[]

View File

@ -159,7 +159,7 @@ describe('useOrderListData Hook', () => {
expect(loadMock).toHaveBeenCalled();
expect(successCallback).toHaveBeenLastCalledWith(
mockDelta.map((item) => item.node),
-1
undefined
);
});
});

View File

@ -9,7 +9,7 @@ const getLastRow = (
blockLength: number,
totalCount?: number
) => {
let lastRow = -1;
let lastRow = undefined;
if (totalCount !== undefined) {
if (!totalCount) {
lastRow = 0;
@ -50,9 +50,15 @@ export const makeInfiniteScrollGetRows =
const rowsThisBlock = data.current
? data.current.slice(startRow, endRow).map((edge) => edge?.node)
: [];
const lastRow =
getLastRow(startRow, endRow, rowsThisBlock.length, totalCount.current) -
newRows.current;
const currentLastNumber = getLastRow(
startRow,
endRow,
rowsThisBlock.length,
totalCount.current
);
const lastRow = currentLastNumber
? currentLastNumber - newRows.current
: currentLastNumber;
successCallback(rowsThisBlock, lastRow);
} catch (e) {
failCallback();