Skip to content

Commit

Permalink
Finish pagination
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Huang <[email protected]>
  • Loading branch information
aar0nTw authored and kentwelcome committed Dec 9, 2021
1 parent 2ffee54 commit 25840ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/ListImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export default function ListImage() {
key: 'imageLabel',
width: '10%',
render: (imageLabel) => {
console.log(imageLabel, 111);
if (imageLabel.length <= 0) {
return <></>;
}
Expand Down
35 changes: 30 additions & 5 deletions src/ListRemoteImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
DockerHubImage,
} from './electron/DockerHubAdapter';

const PAGE_SIZE = 10;

interface ImageTag {
key: any;
name: string;
Expand All @@ -29,6 +31,8 @@ export default function ListRemoteImages() {
const [tagsLoading, setTagsLoading] = useState({});
const [repos, setRepos] = useState<Partial<DockerHubRepository>[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [totalSize, setTotalSize] = useState<number>(0);
const [currentPage, setCurrentPage] = useState<number>(1);

const expandedRowRender = (
record: Partial<DockerHubRepository>,
Expand Down Expand Up @@ -163,16 +167,23 @@ export default function ListRemoteImages() {
});
};

const genFetchRepo = () => {
const genFetchRepo = (page = 1, pageSize = PAGE_SIZE) => {
return async () => {
setLoading(true);
const { repositories, errorMsg } = (await send(
'list-dockerhub-repositories', {page: 1, pageSize: 100}
)) as { repositories: DockerHubRepository[]; errorMsg: string };
const { repositories, errorMsg, count } = (await send(
'list-dockerhub-repositories',
{ page, pageSize }
)) as {
repositories: DockerHubRepository[];
errorMsg: string;
count: number;
};
setTotalSize(count);
if (errorMsg) {
errorNotificationHandler(errorMsg);
} else {
setRepos(repositories);
setCurrentPage(page);
}
setLoading(false);
};
Expand Down Expand Up @@ -262,7 +273,21 @@ export default function ListRemoteImages() {
className='repo-table'
columns={columns}
dataSource={repos}
pagination={false}
pagination={
totalSize / PAGE_SIZE > 1
? {
position: ['topLeft', 'bottomLeft'],
current: currentPage,
defaultCurrent: 1,
size: 'default',
pageSize: PAGE_SIZE,
total: totalSize,
onChange: (page, pageSize) => {
genFetchRepo(page, pageSize)();
},
}
: false
}
loading={loading}
expandable={{
expandedRowRender,
Expand Down

0 comments on commit 25840ff

Please sign in to comment.