Skip to content

Commit

Permalink
Add lastItem to ScrollerGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
garryxiao committed Dec 2, 2024
1 parent ad85e9b commit 036f689
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etsoo/react",
"version": "1.8.3",
"version": "1.8.4",
"description": "TypeScript ReactJs UI Independent Framework",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -48,7 +48,7 @@
"@emotion/css": "^11.13.5",
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@etsoo/appscript": "^1.5.68",
"@etsoo/appscript": "^1.5.76",
"@etsoo/notificationbase": "^1.1.54",
"@etsoo/shared": "^1.2.55",
"react": "^18.3.1",
Expand Down
10 changes: 9 additions & 1 deletion src/components/GridLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ export interface GridLoader<T extends object> {
/**
* Load data
*/
loadData: (props: GridLoadDataProps) => PromiseLike<T[] | null | undefined>;
loadData: (
props: GridLoadDataProps,
lastItem?: T
) => PromiseLike<T[] | null | undefined>;

/**
* Handler for init load
Expand Down Expand Up @@ -147,6 +150,11 @@ type GridLoaderProps<T> = {
*/
autoLoad: boolean;

/**
* Last loaded item
*/
lastItem?: T;

/**
* Last loaded items
*/
Expand Down
3 changes: 2 additions & 1 deletion src/components/ScrollerGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,15 @@ export const ScrollerGrid = <T extends object>(props: ScrollerGridProps<T>) => {
data
};

loadData(loadProps).then((result) => {
loadData(loadProps, refs.current.lastItem).then((result) => {
if (result == null || refs.current.isMounted === false) {
return;
}
refs.current.isMounted = true;

const newItems = result.length;
refs.current.lastLoadedItems = newItems;
refs.current.lastItem = result.at(-1);
refs.current.isNextPageLoading = false;
refs.current.hasNextPage = newItems >= refs.current.queryPaging.batchSize;

Expand Down

0 comments on commit 036f689

Please sign in to comment.