Skip to content

Commit 1d52b7e

Browse files
committed
Refactor containers
1 parent 5fcb46d commit 1d52b7e

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

src/main.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Participant, Match, MatchResults, ParticipantResult, StageType } from '
33
import { splitBy, getRanking, getOriginAbbreviation } from './helpers';
44
import * as dom from './dom';
55
import * as lang from './lang';
6-
import { Config, Connection, FinalType, MatchLocation, OriginHint, RankingItem, RoundName, ViewerData } from './types';
6+
import { Config, Connection, FinalType, MatchLocation, OriginHint, ParticipantContainers, RankingItem, RoundName, ViewerData } from './types';
77

88
export class BracketsViewer {
99

@@ -305,49 +305,47 @@ export class BracketsViewer {
305305
* @param roundNumber Number of the round.
306306
*/
307307
private createTeam(participant: ParticipantResult | null, originHint: OriginHint, matchLocation: MatchLocation, roundNumber?: number): HTMLElement {
308-
const participantContainer = dom.createParticipantContainer();
309-
const nameContainer = dom.createNameContainer();
310-
const resultContainer = dom.createResultContainer();
308+
const containers: ParticipantContainers = {
309+
participant: dom.createParticipantContainer(),
310+
name: dom.createNameContainer(),
311+
result: dom.createResultContainer(),
312+
}
311313

312314
if (participant === null)
313-
nameContainer.innerText = 'BYE';
315+
containers.name.innerText = 'BYE';
314316
else
315-
this.renderParticipant(participantContainer, nameContainer, resultContainer, participant, originHint, matchLocation, roundNumber);
317+
this.renderParticipant(containers, participant, originHint, matchLocation, roundNumber);
316318

317-
participantContainer.append(nameContainer, resultContainer);
319+
containers.participant.append(containers.name, containers.result);
318320

319321
if (participant && participant.id !== null)
320-
this.setupMouseHover(participant.id, participantContainer);
322+
this.setupMouseHover(participant.id, containers.participant);
321323

322-
return participantContainer;
324+
return containers.participant;
323325
}
324326

325-
// TODO: group containers into an object
326-
327327
/**
328328
* Renders a participant.
329329
*
330-
* @param participantContainer The participant container.
331-
* @param nameContainer The name container.
332-
* @param resultContainer The result container.
330+
* @param containers Containers for the participant.
333331
* @param participant The participant result.
334332
* @param originHint Origin hint for the match.
335333
* @param matchLocation Location of the match.
336334
* @param roundNumber Number of the round.
337335
*/
338-
private renderParticipant(participantContainer: HTMLElement, nameContainer: HTMLElement, resultContainer: HTMLElement, participant: ParticipantResult, originHint: OriginHint, matchLocation: MatchLocation, roundNumber?: number): void {
336+
private renderParticipant(containers: ParticipantContainers, participant: ParticipantResult, originHint: OriginHint, matchLocation: MatchLocation, roundNumber?: number): void {
339337
const found = this.participants.find(item => item.id === participant.id);
340338

341339
if (found) {
342-
nameContainer.innerText = found.name;
343-
this.renderTeamOrigin(nameContainer, participant, matchLocation, roundNumber);
340+
containers.name.innerText = found.name;
341+
this.renderTeamOrigin(containers.name, participant, matchLocation, roundNumber);
344342
} else
345-
this.renderHint(nameContainer, participant, originHint, matchLocation);
343+
this.renderHint(containers.name, participant, originHint, matchLocation);
346344

347-
resultContainer.innerText = `${participant.score || '-'}`;
345+
containers.result.innerText = `${participant.score || '-'}`;
348346

349-
dom.setupWin(participantContainer, resultContainer, participant);
350-
dom.setupLoss(participantContainer, resultContainer, participant);
347+
dom.setupWin(containers.participant, containers.result, participant);
348+
dom.setupLoss(containers.participant, containers.result, participant);
351349
}
352350

353351
/**

src/types.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,13 @@ export type RankingMap = { [id: number]: RankingItem };
134134
/**
135135
* Definition of a ranking.
136136
*/
137-
export type Ranking = RankingItem[];
137+
export type Ranking = RankingItem[];
138+
139+
/**
140+
* Structure containing all the containers for a participant.
141+
*/
142+
export interface ParticipantContainers {
143+
participant: HTMLElement,
144+
name: HTMLElement,
145+
result: HTMLElement,
146+
}

0 commit comments

Comments
 (0)