Skip to content

Commit d4bd3c6

Browse files
committed
Lint files
1 parent 55b514b commit d4bd3c6

File tree

3 files changed

+79
-59
lines changed

3 files changed

+79
-59
lines changed

src/form.ts

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,20 @@ export function stageFormCreator(configuration: FormConfiguration, submitCallabl
7474
createMaskFields(configuration, 'single_elimination', parent, submitCallable);
7575
}
7676

77-
export function updateFormCreator(configuration: FormConfiguration, changeCallable: CallbackFunction) {
77+
/**
78+
* Creates a DOM form to update the current stage.
79+
*
80+
* @param configuration HTML element IDs to render this form to
81+
* @param changeCallable Callback function - what should happen onClick on the forms submit button?
82+
*/
83+
export function updateFormCreator(configuration: FormConfiguration, changeCallable: CallbackFunction): void {
7884
const urlParams = new URLSearchParams(window.location.search);
7985
const id = urlParams.get('id') ?? 0;
8086

87+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
8188
const storedBrackets = JSON.parse(localStorage.getItem('brackets') ?? '');
82-
const currentBracket = storedBrackets[id] as Database
89+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
90+
const currentBracket = storedBrackets[id] as Database;
8391

8492
const parent = document.getElementById(configuration.parent_id);
8593

@@ -96,15 +104,15 @@ export function updateFormCreator(configuration: FormConfiguration, changeCallab
96104
stageSelector.onchange = (): void => {
97105
removeMaskFields(parent);
98106

99-
const stage = ((<HTMLInputElement>stageSelector).value || 'single_elimination') as StageType
107+
const stage = ((<HTMLInputElement>stageSelector).value || 'single_elimination') as StageType;
100108
createMaskFields(configuration, stage, parent, changeCallable, 'Edit');
101109
};
102110

103111
const teamCountInput = document.getElementById(configuration.html_team_count_input_id)!;
104-
teamCountInput.oninput = () => {
105-
const stage = ((<HTMLInputElement>stageSelector).value || 'single_elimination') as StageType
106-
applyForm(configuration, stage, changeCallable)
107-
}
112+
teamCountInput.oninput = (): void => {
113+
const stage = ((<HTMLInputElement>stageSelector).value || 'single_elimination') as StageType;
114+
applyForm(configuration, stage, changeCallable);
115+
};
108116

109117
createMaskFields(configuration, currentBracket.stage[0].type, parent, changeCallable, 'Edit');
110118
}
@@ -117,20 +125,24 @@ export function updateFormCreator(configuration: FormConfiguration, changeCallab
117125
function removeMaskFields(parent: HTMLElement): void {
118126
[...parent.children]
119127
.filter(c => !c.classList.contains('base-input'))
120-
.forEach(c => c.remove())
128+
.forEach(c => c.remove());
121129
}
122130

123131

124132
/**
125133
* @param parent HTMLElement
126134
* @param configuration FormConfiguration
135+
* @param setDefaultValues Whether to set default values for the form
136+
* @param showTeamNamesInput Whether to show the input for team names
127137
*/
128138
function createBaseMask(parent: HTMLElement, configuration: FormConfiguration, setDefaultValues = false, showTeamNamesInput = true): void {
129139
const urlParams = new URLSearchParams(window.location.search);
130140
const id = urlParams.get('id') ?? 0;
131141

142+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
132143
const storedBrackets = JSON.parse(localStorage.getItem('brackets') ?? '');
133-
const currentBracket = storedBrackets[id] as Database
144+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
145+
const currentBracket = storedBrackets[id] as Database;
134146

135147
// Name
136148
createInput(
@@ -142,7 +154,7 @@ function createBaseMask(parent: HTMLElement, configuration: FormConfiguration, s
142154
setDefaultValues ? currentBracket.stage[0].name : undefined,
143155
undefined,
144156
1,
145-
'base-input'
157+
'base-input',
146158
);
147159

148160
// Team names
@@ -153,7 +165,7 @@ function createBaseMask(parent: HTMLElement, configuration: FormConfiguration, s
153165
t('form-creator.team-label'),
154166
t('form-creator.team-label-placeholder'),
155167
undefined,
156-
'base-input'
168+
'base-input',
157169
);
158170
}
159171

@@ -167,7 +179,7 @@ function createBaseMask(parent: HTMLElement, configuration: FormConfiguration, s
167179
setDefaultValues ? currentBracket.participant.length.toString() : '',
168180
'1',
169181
undefined,
170-
'base-input'
182+
'base-input',
171183
);
172184

173185
// Stage selector
@@ -177,7 +189,7 @@ function createBaseMask(parent: HTMLElement, configuration: FormConfiguration, s
177189
t('form-creator.stage-selector-label'),
178190
stageTypes,
179191
setDefaultValues ? currentBracket.stage[0].type : undefined,
180-
'base-input'
192+
'base-input',
181193
);
182194
}
183195

@@ -188,6 +200,7 @@ function createBaseMask(parent: HTMLElement, configuration: FormConfiguration, s
188200
* @param stage Which type of stage are we building?
189201
* @param parent The parent DOM
190202
* @param submitCallback the callable to call when the data got created
203+
* @param submitBtnText Text of the submit button
191204
*/
192205
function createMaskFields(config: FormConfiguration, stage: StageType, parent: HTMLElement, submitCallback: CallbackFunction, submitBtnText?: string): void {
193206
switch (stage) {
@@ -236,7 +249,7 @@ function createMaskFields(config: FormConfiguration, stage: StageType, parent: H
236249
config.html_double_elimination_seed_textarea_id,
237250
t('form-creator.seed-order-label'),
238251
t('form-creator.double-elimination-seed-order-placeholder'),
239-
'natural'
252+
'natural',
240253
);
241254

242255
break;
@@ -253,15 +266,22 @@ function createMaskFields(config: FormConfiguration, stage: StageType, parent: H
253266
submitBtnWrapper.appendChild(submitBtn);
254267

255268
submitBtn.onclick = (): void => {
256-
applyForm(config, stage, submitCallback)
269+
applyForm(config, stage, submitCallback);
257270
};
258271

259272
parent.appendChild(submitBtnWrapper);
260273
}
261274

262-
function applyForm(config: FormConfiguration, stage: StageType, submitCallback: CallbackFunction) {
275+
/**
276+
* Apply a form when click on submit
277+
*
278+
* @param config HTML element IDs to render this form to
279+
* @param stage Which type of stage are we building?
280+
* @param submitCallback the callable to call when the data got created
281+
*/
282+
function applyForm(config: FormConfiguration, stage: StageType, submitCallback: CallbackFunction): void {
263283
let payload: InputStage;
264-
let teamNamesValue: string
284+
let teamNamesValue: string;
265285

266286
switch (stage) {
267287
case 'round_robin':
@@ -287,14 +307,14 @@ function applyForm(config: FormConfiguration, stage: StageType, submitCallback:
287307
type: stage,
288308
};
289309

290-
teamNamesValue = (<HTMLTextAreaElement>document.getElementById(config.html_team_names_input_id))?.value
310+
teamNamesValue = (<HTMLTextAreaElement>document.getElementById(config.html_team_names_input_id))?.value;
291311

292-
if (teamNamesValue) {
293-
payload.seeding = teamNamesValue.split(',')
294-
} else {
295-
const teamCount = parseInt((<HTMLTextAreaElement>document.getElementById(config.html_team_count_input_id)).value)
296-
payload.seeding = Array.from({ length: teamCount }).map((_, i) => `Team ${i + 1}`)
297-
roundRobinSettings.size = helpers.getNearestPowerOfTwo(teamCount)
312+
if (teamNamesValue)
313+
payload.seeding = teamNamesValue.split(',');
314+
else {
315+
const teamCount = parseInt((<HTMLTextAreaElement>document.getElementById(config.html_team_count_input_id)).value);
316+
payload.seeding = Array.from({ length: teamCount }).map((_, i) => `Team ${i + 1}`);
317+
roundRobinSettings.size = helpers.getNearestPowerOfTwo(teamCount);
298318
}
299319

300320
break;
@@ -316,14 +336,14 @@ function applyForm(config: FormConfiguration, stage: StageType, submitCallback:
316336
type: stage,
317337
};
318338

319-
teamNamesValue = (<HTMLTextAreaElement>document.getElementById(config.html_team_names_input_id))?.value
339+
teamNamesValue = (<HTMLTextAreaElement>document.getElementById(config.html_team_names_input_id))?.value;
320340

321-
if (teamNamesValue) {
322-
payload.seeding = teamNamesValue.split(',')
323-
} else {
324-
const teamCount = parseInt((<HTMLTextAreaElement>document.getElementById(config.html_team_count_input_id)).value)
325-
payload.seeding = Array.from({ length: teamCount }).map((_, i) => `Team ${i + 1}`)
326-
singleEliminationSettings.size = helpers.getNearestPowerOfTwo(teamCount)
341+
if (teamNamesValue)
342+
payload.seeding = teamNamesValue.split(',');
343+
else {
344+
const teamCount = parseInt((<HTMLTextAreaElement>document.getElementById(config.html_team_count_input_id)).value);
345+
payload.seeding = Array.from({ length: teamCount }).map((_, i) => `Team ${i + 1}`);
346+
singleEliminationSettings.size = helpers.getNearestPowerOfTwo(teamCount);
327347
}
328348

329349
break;
@@ -348,14 +368,14 @@ function applyForm(config: FormConfiguration, stage: StageType, submitCallback:
348368
type: stage,
349369
};
350370

351-
teamNamesValue = (<HTMLTextAreaElement>document.getElementById(config.html_team_names_input_id))?.value
371+
teamNamesValue = (<HTMLTextAreaElement>document.getElementById(config.html_team_names_input_id))?.value;
352372

353-
if (teamNamesValue) {
354-
payload.seeding = teamNamesValue.split(',')
355-
} else {
356-
const teamCount = parseInt((<HTMLTextAreaElement>document.getElementById(config.html_team_count_input_id)).value)
357-
payload.seeding = Array.from({ length: teamCount }).map((_, i) => `Team ${i + 1}`)
358-
doubleEliminationSettings.size = helpers.getNearestPowerOfTwo(teamCount)
373+
if (teamNamesValue)
374+
payload.seeding = teamNamesValue.split(',');
375+
else {
376+
const teamCount = parseInt((<HTMLTextAreaElement>document.getElementById(config.html_team_count_input_id)).value);
377+
payload.seeding = Array.from({ length: teamCount }).map((_, i) => `Team ${i + 1}`);
378+
doubleEliminationSettings.size = helpers.getNearestPowerOfTwo(teamCount);
359379
}
360380

361381
break;
@@ -433,9 +453,9 @@ function baseValidation(config: FormConfiguration): void {
433453
if (!name || name === '')
434454
throw new DOMException('No name provided.');
435455

436-
const teamNamesValue = (<HTMLInputElement>document.getElementById(config.html_team_names_input_id))?.value
456+
const teamNamesValue = (<HTMLInputElement>document.getElementById(config.html_team_names_input_id))?.value;
437457
const teams = teamNamesValue ? teamNamesValue.split(',') : [];
438-
const teamCount = teams.length || parseInt((<HTMLInputElement>document.getElementById(config.html_team_count_input_id)).value)
458+
const teamCount = teams.length || parseInt((<HTMLInputElement>document.getElementById(config.html_team_count_input_id)).value);
439459

440460
if (teamCount < 2)
441461
throw new DOMException('Invalid team amount provided.');
@@ -451,6 +471,7 @@ function baseValidation(config: FormConfiguration): void {
451471
* @param labelText the text for the label of the textarea
452472
* @param textareaPlaceholder the placeholder for the textarea
453473
* @param textareaDefaultValue the default value for the textarea - if NULL or UNDEFINED this is not set
474+
* @param className Class name to give to the wrapper
454475
*/
455476
function createTextarea(parent: HTMLElement, textareaId: string, labelText: string, textareaPlaceholder: string, textareaDefaultValue?: string, className?: string): void {
456477
const wrapper = document.createElement('div');
@@ -466,9 +487,8 @@ function createTextarea(parent: HTMLElement, textareaId: string, labelText: stri
466487
if (null !== textareaDefaultValue && undefined !== textareaDefaultValue)
467488
textarea.value = textareaDefaultValue;
468489

469-
if (className) {
470-
wrapper.classList.add(className)
471-
}
490+
if (className)
491+
wrapper.classList.add(className);
472492

473493
wrapper.appendChild(label);
474494
wrapper.appendChild(textarea);
@@ -485,6 +505,7 @@ function createTextarea(parent: HTMLElement, textareaId: string, labelText: stri
485505
* @param inputDefaultValue the default value for the input - if NULL or UNDEFINED this is not set
486506
* @param inputMinValue the min value for the input - if NULL or UNDEFINED this is not set
487507
* @param inputMinLengthValue the minLength value for the input - if NULL or UNDEFINED this is not set
508+
* @param className Class name to give to the wrapper
488509
*/
489510
function createInput(parent: HTMLElement, inputType: string, inputId: string, labelText: string, inputPlaceholder?: string, inputDefaultValue?: string, inputMinValue?: string, inputMinLengthValue?: number, className?: string): void {
490511
const wrapper = document.createElement('div');
@@ -509,9 +530,8 @@ function createInput(parent: HTMLElement, inputType: string, inputId: string, la
509530
if (null !== inputMinLengthValue && undefined !== inputMinLengthValue)
510531
input.minLength = inputMinLengthValue;
511532

512-
if (className) {
513-
wrapper.classList.add(className)
514-
}
533+
if (className)
534+
wrapper.classList.add(className);
515535

516536
wrapper.appendChild(label);
517537
wrapper.appendChild(input);
@@ -524,6 +544,8 @@ function createInput(parent: HTMLElement, inputType: string, inputId: string, la
524544
* @param selectId The ID of the generated select
525545
* @param labelText The text of the label for the generated select
526546
* @param options The options to display in select
547+
* @param selectedOption Which option should be selected by default
548+
* @param className Class name to give to the wrapper
527549
*/
528550
function createSelect(parent: HTMLElement, selectId: string, labelText: string, options: string[], selectedOption?: string, className?: string): void {
529551
const wrapper = document.createElement('div');
@@ -537,9 +559,8 @@ function createSelect(parent: HTMLElement, selectId: string, labelText: string,
537559

538560
createOptions(select, options, selectedOption);
539561

540-
if (className) {
541-
wrapper.classList.add(className)
542-
}
562+
if (className)
563+
wrapper.classList.add(className);
543564

544565
wrapper.appendChild(label);
545566
wrapper.appendChild(select);
@@ -550,14 +571,15 @@ function createSelect(parent: HTMLElement, selectId: string, labelText: string,
550571
/**
551572
* @param optionSwitch HTMLElement to add the options to
552573
* @param options string list of possible options
574+
* @param selectedOption Which option should be selected by default
553575
*/
554576
function createOptions(optionSwitch: HTMLElement, options: string[], selectedOption?: string): void {
555577
options.forEach(option => {
556578
const optionElement = document.createElement('option');
557579
optionElement.innerText = option;
558-
if (option === selectedOption) {
559-
optionElement.selected = true
560-
}
580+
if (option === selectedOption)
581+
optionElement.selected = true;
582+
561583
optionSwitch.appendChild(optionElement);
562584
});
563585
}

src/main.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export class BracketsViewer {
7373
this._onMatchClick = config.onMatchClick;
7474

7575
this.participants = data.participants;
76-
7776
data.participants.forEach(participant => this.participantRefs[participant.id] = []);
7877

7978
data.stages.forEach(stage => this.renderStage(root, {
@@ -82,10 +81,9 @@ export class BracketsViewer {
8281
matches: data.matches.filter(match => match.stage_id === stage.id),
8382
}));
8483

85-
const target = findRoot(config?.selector)
86-
if (config?.clear) {
87-
target.innerHTML = ''
88-
}
84+
const target = findRoot(config?.selector);
85+
if (config?.clear)
86+
target.innerHTML = '';
8987

9088
target.append(root);
9189
}
@@ -325,7 +323,7 @@ export class BracketsViewer {
325323
roundNumber,
326324
roundCount,
327325
groupType: lang.toI18nKey('final_group'),
328-
finalType: lang.toI18nKey(finalType)
326+
finalType: lang.toI18nKey(finalType),
329327
}, lang.getRoundName);
330328

331329
const roundContainer = dom.createRoundContainer(finalMatches[roundIndex].round_id, roundName);

src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export type RoundNameInfo = {
133133
finalType: ToI18nKey<FinalType>,
134134
roundNumber: number,
135135
roundCount: number,
136-
}
136+
};
137137

138138
/**
139139
* A function returning a round name based on its number and the count of rounds.

0 commit comments

Comments
 (0)