✨ Refactor tournament loading logic to use loadMoreState for improved error handling and state management
This commit is contained in:
@@ -628,23 +628,25 @@ async function testListTournaments(resetPagination = true) {
|
||||
async function loadMoreTournaments() {
|
||||
if (apiVersion.value === 'v1') return; // v1 doesn't support pagination
|
||||
|
||||
loadingMore.value = true;
|
||||
currentPage.value++;
|
||||
|
||||
try {
|
||||
const result = await queryAllTournaments(client.value, {
|
||||
const result = await loadMoreState.execute(async () => {
|
||||
const newResults = await queryAllTournaments(client.value, {
|
||||
page: currentPage.value,
|
||||
per_page: 100,
|
||||
scopeType: tournamentScope.value
|
||||
});
|
||||
|
||||
hasNextPage.value = newResults.length === perPage.value;
|
||||
return newResults;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
// Append new results to existing tournaments
|
||||
tournaments.value = [...tournaments.value, ...result];
|
||||
hasNextPage.value = result.length === perPage.value;
|
||||
} catch (err) {
|
||||
currentPage.value--; // Revert on error
|
||||
handleError(err);
|
||||
} finally {
|
||||
loadingMore.value = false;
|
||||
} else {
|
||||
// Revert page increment on error
|
||||
currentPage.value--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user