✨ 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) {
|
async function testListTournaments(resetPagination = true) {
|
||||||
loading.value = true;
|
|
||||||
error.value = null;
|
|
||||||
|
|
||||||
if (resetPagination) {
|
if (resetPagination) {
|
||||||
currentPage.value = 1;
|
currentPage.value = 1;
|
||||||
tournaments.value = null;
|
|
||||||
searchQuery.value = '';
|
searchQuery.value = '';
|
||||||
expandedTournamentId.value = null;
|
expandedTournamentId.value = null;
|
||||||
tournamentDetails.value = null;
|
tournamentDetailsState.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await tournamentListState.execute(async () => {
|
||||||
if (apiVersion.value === 'v1') {
|
if (apiVersion.value === 'v1') {
|
||||||
// v1 doesn't support pagination
|
// v1 doesn't support pagination
|
||||||
const result = await client.value.tournaments.list();
|
const result = await client.value.tournaments.list();
|
||||||
tournaments.value = result;
|
|
||||||
totalTournaments.value = result.length;
|
totalTournaments.value = result.length;
|
||||||
hasNextPage.value = false;
|
hasNextPage.value = false;
|
||||||
|
return result;
|
||||||
} else {
|
} else {
|
||||||
// v2.1 - Query all tournament states (pending, in_progress, ended) in parallel
|
// v2.1 - Query all tournament states (pending, in_progress, ended) in parallel
|
||||||
// USER scope returns tournaments you have access to:
|
// USER scope returns tournaments you have access to:
|
||||||
@@ -622,15 +618,11 @@ async function testListTournaments(resetPagination = true) {
|
|||||||
results: result
|
results: result
|
||||||
});
|
});
|
||||||
|
|
||||||
tournaments.value = result;
|
|
||||||
totalTournaments.value = result.length;
|
totalTournaments.value = result.length;
|
||||||
hasNextPage.value = result.length >= 100;
|
hasNextPage.value = result.length >= 100;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
});
|
||||||
handleError(err);
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadMoreTournaments() {
|
async function loadMoreTournaments() {
|
||||||
|
|||||||
Reference in New Issue
Block a user