Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display issue in explorer indexers #981

Merged
merged 4 commits into from
Aug 6, 2024

Conversation

Kevin101Zhang
Copy link
Contributor

@Kevin101Zhang Kevin101Zhang commented Aug 5, 2024

explore seems to be missing a few indexers and the reason was due to pagination starting from 0. so on load it would grab the intial 50 and then onclick for loadmore it would still grab the 0-50 already on display.

fix: changes page to intialize to 1.

Initial Load (0-49) Indexers Loaded
First Click (page = 1): Loads indexers from 50 to 99.
Second Click (page = 2): Loads indexers from 100 to 149.

const handleLoadMore = () => {
  const start = page * PAGE_SIZE; // FIRST: 1*50 = 50 -> SECOND: 2*50 = 100
  const end = start + PAGE_SIZE; //  FIRST: 50+50 = 100 -> SECOND: 100+50 = 150
  const newIndexers = indexers.slice(start, end); // FIRST CLICK: 50-99 -> SECOND CLICK: 100-149
  setCurrentPageIndexer([...currentPageIndexer, ...newIndexers]); 
  // FIRST: 0-49 + 50-99, SECOND: 0-99 + 100 - 149
  setPage(page + 1); 
};

@Kevin101Zhang Kevin101Zhang linked an issue Aug 5, 2024 that may be closed by this pull request
@Kevin101Zhang Kevin101Zhang marked this pull request as ready for review August 5, 2024 22:13
@Kevin101Zhang Kevin101Zhang requested a review from a team as a code owner August 5, 2024 22:13
@@ -40,7 +40,7 @@ const [hasMetadataRendered, setHasMetadataRendered] = useState(false);
const [indexers, setIndexers] = useState([]);
const [total, setTotal] = useState(0);
const [currentPageIndexer, setCurrentPageIndexer] = useState([]);
const [page, setPage] = useState(0);
const [page, setPage] = useState(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setPage being initialized to 1 is confusing. Instead, could you modify the handleLoadMore to do something like:

const newPage = page + 1;
// Do load more logic using newPage
setPage(newPage);

I feel the above reads a little nicer? Ideally, you would do setPage first, but I wonder if there could be lag in setting the value, so I am fine making that the last item.

Copy link
Contributor Author

@Kevin101Zhang Kevin101Zhang Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I was the one who did it in a more unconventional setting before.

It's more common to start the initial page state at 1. This is because pagination systems often use 1-based indexing, where the first page is labeled as page 1. Some systems and APIs use 0-based indexing, where the first page is labeled as page 0 but for consistency and user-friendliness, starting at 1 is generally more intuitive, as it aligns with typical expectations

Edit:

Ah yeah I did some more research. Redux and other tools define it index based. Will change this

@Kevin101Zhang Kevin101Zhang merged commit 24eac56 into main Aug 6, 2024
4 checks passed
@Kevin101Zhang Kevin101Zhang deleted the 980-investigate-inconsistencies-on-fe branch August 6, 2024 19:09
@darunrs darunrs mentioned this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

display issue in explorer indexers
2 participants