✨ Refactor tournament listing logic to use state management and simplify error handling
This commit is contained in:
@@ -564,24 +564,20 @@ function getTournamentProp(tournament, prop) {
|
||||
}
|
||||
|
||||
async function testListTournaments(resetPagination = true) {
|
||||
loading.value = true;
|
||||
error.value = null;
|
||||
|
||||
if (resetPagination) {
|
||||
currentPage.value = 1;
|
||||
tournaments.value = null;
|
||||
searchQuery.value = '';
|
||||
expandedTournamentId.value = null;
|
||||
tournamentDetails.value = null;
|
||||
tournamentDetailsState.reset();
|
||||
}
|
||||
|
||||
try {
|
||||
await tournamentListState.execute(async () => {
|
||||
if (apiVersion.value === 'v1') {
|
||||
// v1 doesn't support pagination
|
||||
const result = await client.value.tournaments.list();
|
||||
tournaments.value = result;
|
||||
totalTournaments.value = result.length;
|
||||
hasNextPage.value = false;
|
||||
return result;
|
||||
} else {
|
||||
// v2.1 - Query all tournament states (pending, in_progress, ended) in parallel
|
||||
// USER scope returns tournaments you have access to:
|
||||
@@ -622,15 +618,11 @@ async function testListTournaments(resetPagination = true) {
|
||||
results: result
|
||||
});
|
||||
|
||||
tournaments.value = result;
|
||||
totalTournaments.value = result.length;
|
||||
hasNextPage.value = result.length >= 100;
|
||||
return result;
|
||||
}
|
||||
} catch (err) {
|
||||
handleError(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function loadMoreTournaments() {
|
||||
|
||||
Reference in New Issue
Block a user