mirror of
https://github.com/Pandipipas/scoreko-dev.git
synced 2026-06-06 03:32:06 +00:00
Refactor and simplify start.gg import flow code
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user