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 {
|
interface TemporaryStartGGPlayerMeta {
|
||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
tournamentSlug: string;
|
tournamentSlug: string;
|
||||||
tournamentName: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TemporaryStartGGPlayersMap = Record<string, TemporaryStartGGPlayerMeta>;
|
type TemporaryStartGGPlayersMap = Record<string, TemporaryStartGGPlayerMeta>;
|
||||||
@@ -103,7 +102,7 @@ const loadingTournaments = ref(false);
|
|||||||
const tournamentsError = ref('');
|
const tournamentsError = ref('');
|
||||||
const isImportDialogOpen = ref(false);
|
const isImportDialogOpen = ref(false);
|
||||||
const loadingTournamentPlayers = ref(false);
|
const loadingTournamentPlayers = ref(false);
|
||||||
const selectedTournament = ref<StartGGTournament | null>(null);
|
const importingTournament = ref<StartGGTournament | null>(null);
|
||||||
const startGGPlayers = ref<StartGGImportedPlayer[]>([]);
|
const startGGPlayers = ref<StartGGImportedPlayer[]>([]);
|
||||||
const selectedStartGGPlayerIds = ref<string[]>([]);
|
const selectedStartGGPlayerIds = ref<string[]>([]);
|
||||||
const selectedTournamentSlug = ref('');
|
const selectedTournamentSlug = ref('');
|
||||||
@@ -153,14 +152,12 @@ const loadTemporaryStartGGPlayers = (): TemporaryStartGGPlayersMap => {
|
|||||||
const candidate = value as Record<string, unknown>;
|
const candidate = value as Record<string, unknown>;
|
||||||
const expiresAt = Number(candidate.expiresAt);
|
const expiresAt = Number(candidate.expiresAt);
|
||||||
const tournamentSlug = String(candidate.tournamentSlug || '').trim();
|
const tournamentSlug = String(candidate.tournamentSlug || '').trim();
|
||||||
const tournamentName = String(candidate.tournamentName || '').trim();
|
|
||||||
if (!Number.isFinite(expiresAt) || expiresAt <= 0 || !tournamentSlug) {
|
if (!Number.isFinite(expiresAt) || expiresAt <= 0 || !tournamentSlug) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
result[playerId] = {
|
result[playerId] = {
|
||||||
expiresAt,
|
expiresAt,
|
||||||
tournamentSlug,
|
tournamentSlug,
|
||||||
tournamentName,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -190,6 +187,7 @@ watch(tournamentOptions, (value) => {
|
|||||||
const selectedTournamentOption = computed(() =>
|
const selectedTournamentOption = computed(() =>
|
||||||
recentTournaments.value.find((item) => item.slug === selectedTournamentSlug.value) ?? null,
|
recentTournaments.value.find((item) => item.slug === selectedTournamentSlug.value) ?? null,
|
||||||
);
|
);
|
||||||
|
const canImportSelectedTournament = computed(() => Boolean(selectedTournamentOption.value));
|
||||||
|
|
||||||
const filterTournaments = (value: string, update: (callback: () => void) => void) => {
|
const filterTournaments = (value: string, update: (callback: () => void) => void) => {
|
||||||
update(() => {
|
update(() => {
|
||||||
@@ -330,7 +328,7 @@ const loadRecentTournaments = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const openStartGGImportDialog = async (tournament: StartGGTournament) => {
|
const openStartGGImportDialog = async (tournament: StartGGTournament) => {
|
||||||
selectedTournament.value = tournament;
|
importingTournament.value = tournament;
|
||||||
isImportDialogOpen.value = true;
|
isImportDialogOpen.value = true;
|
||||||
loadingTournamentPlayers.value = true;
|
loadingTournamentPlayers.value = true;
|
||||||
selectedStartGGPlayerIds.value = [];
|
selectedStartGGPlayerIds.value = [];
|
||||||
@@ -368,7 +366,7 @@ const importSelectedStartGGPlayers = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const nextMeta = { ...temporaryStartGGPlayers.value };
|
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 fallbackEndAt = (tournament?.startAt ?? Math.floor(Date.now() / 1000)) + STARTGG_TEMP_FALLBACK_DURATION_SECONDS;
|
||||||
const expiresAt = tournament?.endAt ?? fallbackEndAt;
|
const expiresAt = tournament?.endAt ?? fallbackEndAt;
|
||||||
|
|
||||||
@@ -385,7 +383,6 @@ const importSelectedStartGGPlayers = () => {
|
|||||||
nextMeta[player.id] = {
|
nextMeta[player.id] = {
|
||||||
expiresAt,
|
expiresAt,
|
||||||
tournamentSlug: tournament.slug,
|
tournamentSlug: tournament.slug,
|
||||||
tournamentName: tournament.name,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -642,7 +639,7 @@ onBeforeUnmount(() => {
|
|||||||
</QSelect>
|
</QSelect>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="selectedTournamentOption"
|
v-if="canImportSelectedTournament"
|
||||||
class="col-auto"
|
class="col-auto"
|
||||||
>
|
>
|
||||||
<QBtn
|
<QBtn
|
||||||
@@ -661,7 +658,7 @@ onBeforeUnmount(() => {
|
|||||||
<QCard class="players-dialog">
|
<QCard class="players-dialog">
|
||||||
<QCardSection>
|
<QCardSection>
|
||||||
<div class="text-h6">
|
<div class="text-h6">
|
||||||
Importar desde {{ selectedTournament?.name || 'start.gg' }}
|
Importar desde {{ importingTournament?.name || 'start.gg' }}
|
||||||
</div>
|
</div>
|
||||||
</QCardSection>
|
</QCardSection>
|
||||||
<QSeparator />
|
<QSeparator />
|
||||||
@@ -817,10 +814,6 @@ onBeforeUnmount(() => {
|
|||||||
width: min(720px, 90vw);
|
width: min(720px, 90vw);
|
||||||
}
|
}
|
||||||
|
|
||||||
.startgg-tournaments-list {
|
|
||||||
max-height: 280px;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.players-underlined-field :deep(.q-field__control) {
|
.players-underlined-field :deep(.q-field__control) {
|
||||||
min-height: 28px;
|
min-height: 28px;
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ interface OAuthConfig {
|
|||||||
interface OAuthSession {
|
interface OAuthSession {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
state: string;
|
state: string;
|
||||||
createdAt: number;
|
|
||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
status: 'pending' | 'completed' | 'error' | 'expired';
|
status: 'pending' | 'completed' | 'error' | 'expired';
|
||||||
token?: string;
|
token?: string;
|
||||||
@@ -91,8 +90,9 @@ const requestStartGG = async <T>(query: string, variables: Record<string, unknow
|
|||||||
return payload.data;
|
return payload.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const countryByCode = new Set(getData().map((country: CountryRecord) => country.code.toUpperCase()));
|
const countries = getData();
|
||||||
const countryByName = new Map(getData().map((country: CountryRecord) => [country.name.toLowerCase(), country.code.toUpperCase()]));
|
const countryByCode = new Set(countries.map((country: CountryRecord) => country.code.toUpperCase()));
|
||||||
|
const countryByName = new Map(countries.map((country: CountryRecord) => [country.name.toLowerCase(), country.code.toUpperCase()]));
|
||||||
|
|
||||||
const resolveCountryCodeFromStartGG = (country: string | null | undefined): string => {
|
const resolveCountryCodeFromStartGG = (country: string | null | undefined): string => {
|
||||||
const raw = (country || '').trim();
|
const raw = (country || '').trim();
|
||||||
@@ -346,12 +346,10 @@ nodecg.listenFor('startgg:createOAuthSession', async (_payload: unknown, ack) =>
|
|||||||
|
|
||||||
const sessionId = randomUUID();
|
const sessionId = randomUUID();
|
||||||
const state = randomUUID();
|
const state = randomUUID();
|
||||||
const now = Date.now();
|
|
||||||
const session: OAuthSession = {
|
const session: OAuthSession = {
|
||||||
sessionId,
|
sessionId,
|
||||||
state,
|
state,
|
||||||
createdAt: now,
|
expiresAt: Date.now() + STARTGG_OAUTH_SESSION_TTL_MS,
|
||||||
expiresAt: now + STARTGG_OAUTH_SESSION_TTL_MS,
|
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
};
|
};
|
||||||
oauthSessions.set(sessionId, session);
|
oauthSessions.set(sessionId, session);
|
||||||
|
|||||||
Reference in New Issue
Block a user