From c36d5ed4231838634fd2d45b39664db06dca4b1d Mon Sep 17 00:00:00 2001 From: Keith Stevens Date: Sun, 15 Jan 2023 20:43:31 +0900 Subject: [PATCH] Array bounds checking --- website/src/components/UsersCell.tsx | 34 +++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/website/src/components/UsersCell.tsx b/website/src/components/UsersCell.tsx index 7f165431..99824090 100644 --- a/website/src/components/UsersCell.tsx +++ b/website/src/components/UsersCell.tsx @@ -62,17 +62,35 @@ const UsersCell = () => { }); const toPreviousPage = () => { - setPagination({ - cursor: users[0].display_name, - direction: "back", - }); + if (users.length >= 0) { + setPagination({ + cursor: users[0].display_name, + direction: "back", + }); + } else { + toast({ + title: "Can not paginate when no users are found", + status: "warning", + duration: 1000, + isClosable: true, + }); + } }; const toNextPage = () => { - setPagination({ - cursor: users[users.length - 1].display_name, - direction: "forward", - }); + if (users.length >= 0) { + setPagination({ + cursor: users[users.length - 1].display_name, + direction: "forward", + }); + } else { + toast({ + title: "Can not paginate when no users are found", + status: "warning", + duration: 1000, + isClosable: true, + }); + } }; // Present users in a naive table.