✨ 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() {
|
async function loadMoreTournaments() {
|
||||||
if (apiVersion.value === 'v1') return; // v1 doesn't support pagination
|
if (apiVersion.value === 'v1') return; // v1 doesn't support pagination
|
||||||
|
|
||||||
loadingMore.value = true;
|
|
||||||
currentPage.value++;
|
currentPage.value++;
|
||||||
|
|
||||||
try {
|
const result = await loadMoreState.execute(async () => {
|
||||||
const result = await queryAllTournaments(client.value, {
|
const newResults = await queryAllTournaments(client.value, {
|
||||||
page: currentPage.value,
|
page: currentPage.value,
|
||||||
per_page: 100,
|
per_page: 100,
|
||||||
scopeType: tournamentScope.value
|
scopeType: tournamentScope.value
|
||||||
});
|
});
|
||||||
|
|
||||||
|
hasNextPage.value = newResults.length === perPage.value;
|
||||||
|
return newResults;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
// Append new results to existing tournaments
|
||||||
tournaments.value = [...tournaments.value, ...result];
|
tournaments.value = [...tournaments.value, ...result];
|
||||||
hasNextPage.value = result.length === perPage.value;
|
} else {
|
||||||
} catch (err) {
|
// Revert page increment on error
|
||||||
currentPage.value--; // Revert on error
|
currentPage.value--;
|
||||||
handleError(err);
|
|
||||||
} finally {
|
|
||||||
loadingMore.value = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user