Refactor and simplify start.gg import flow code

This commit is contained in:
Pandipipas
2026-02-16 01:28:50 +01:00
parent eda3f7b7b9
commit 6dcc2faf70
2 changed files with 10 additions and 19 deletions
+6 -13
View File
@@ -37,7 +37,6 @@ const STARTGG_TEMP_FALLBACK_DURATION_SECONDS = 12 * 60 * 60;
interface TemporaryStartGGPlayerMeta {
expiresAt: number;
tournamentSlug: string;
tournamentName: string;
}
type TemporaryStartGGPlayersMap = Record<string, TemporaryStartGGPlayerMeta>;
@@ -103,7 +102,7 @@ const loadingTournaments = ref(false);
const tournamentsError = ref('');
const isImportDialogOpen = ref(false);
const loadingTournamentPlayers = ref(false);
const selectedTournament = ref<StartGGTournament | null>(null);
const importingTournament = ref<StartGGTournament | null>(null);
const startGGPlayers = ref<StartGGImportedPlayer[]>([]);
const selectedStartGGPlayerIds = ref<string[]>([]);
const selectedTournamentSlug = ref('');
@@ -153,14 +152,12 @@ const loadTemporaryStartGGPlayers = (): TemporaryStartGGPlayersMap => {
const candidate = value as Record<string, unknown>;
const expiresAt = Number(candidate.expiresAt);
const tournamentSlug = String(candidate.tournamentSlug || '').trim();
const tournamentName = String(candidate.tournamentName || '').trim();
if (!Number.isFinite(expiresAt) || expiresAt <= 0 || !tournamentSlug) {
return;
}
result[playerId] = {
expiresAt,
tournamentSlug,
tournamentName,
};
});
@@ -190,6 +187,7 @@ watch(tournamentOptions, (value) => {
const selectedTournamentOption = computed(() =>
recentTournaments.value.find((item) => item.slug === selectedTournamentSlug.value) ?? null,
);
const canImportSelectedTournament = computed(() => Boolean(selectedTournamentOption.value));
const filterTournaments = (value: string, update: (callback: () => void) => void) => {
update(() => {
@@ -330,7 +328,7 @@ const loadRecentTournaments = async () => {
};
const openStartGGImportDialog = async (tournament: StartGGTournament) => {
selectedTournament.value = tournament;
importingTournament.value = tournament;
isImportDialogOpen.value = true;
loadingTournamentPlayers.value = true;
selectedStartGGPlayerIds.value = [];
@@ -368,7 +366,7 @@ const importSelectedStartGGPlayers = () => {
);
const nextMeta = { ...temporaryStartGGPlayers.value };
const tournament = selectedTournament.value;
const tournament = importingTournament.value;
const fallbackEndAt = (tournament?.startAt ?? Math.floor(Date.now() / 1000)) + STARTGG_TEMP_FALLBACK_DURATION_SECONDS;
const expiresAt = tournament?.endAt ?? fallbackEndAt;
@@ -385,7 +383,6 @@ const importSelectedStartGGPlayers = () => {
nextMeta[player.id] = {
expiresAt,
tournamentSlug: tournament.slug,
tournamentName: tournament.name,
};
}
});
@@ -642,7 +639,7 @@ onBeforeUnmount(() => {
</QSelect>
</div>
<div
v-if="selectedTournamentOption"
v-if="canImportSelectedTournament"
class="col-auto"
>
<QBtn
@@ -661,7 +658,7 @@ onBeforeUnmount(() => {
<QCard class="players-dialog">
<QCardSection>
<div class="text-h6">
Importar desde {{ selectedTournament?.name || 'start.gg' }}
Importar desde {{ importingTournament?.name || 'start.gg' }}
</div>
</QCardSection>
<QSeparator />
@@ -817,10 +814,6 @@ onBeforeUnmount(() => {
width: min(720px, 90vw);
}
.startgg-tournaments-list {
max-height: 280px;
overflow: auto;
}
.players-underlined-field :deep(.q-field__control) {
min-height: 28px;