Skip to content

Commit

Permalink
Add title and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Drarig29 committed Jul 9, 2023
1 parent 3a8deef commit 2da6a57
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 78 deletions.
2 changes: 1 addition & 1 deletion dist/brackets-viewer.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/brackets-viewer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/stage-form-creator.min.js

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export function createTitle(title: string): HTMLElement {
return h1;
}

/**
* Creates the title of a popover.
*
* @param title The title to set.
*/
export function createPopoverTitle(title: string): HTMLElement {
const h4 = document.createElement('h4');
h4.innerText = title;
return h4;
}

/**
* Creates a container which contains a round-robin stage.
*
Expand Down Expand Up @@ -129,9 +140,9 @@ export function createMatchContainer(match?: Match | MatchGame): HTMLElement {
* @param status The status to set as tooltip.
* @param onClick Called when the label is clicked.
*/
export function createMatchLabel(label: string, status: string, onClick?: (event: MouseEvent) => void): HTMLElement {
export function createMatchLabel(label: string | undefined, status: string, onClick?: (event: MouseEvent) => void): HTMLElement {
const span = document.createElement('span');
span.innerText = label;
span.innerText = label || '';
span.title = status;
onClick && span.addEventListener('click', onClick);
return span;
Expand Down
20 changes: 15 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Match, ParticipantResult, GroupType, MatchGame } from 'brackets-model';
import { RankingHeader, Ranking, RankingFormula, RankingItem, RankingMap, Side } from './types';
import { RankingHeader, Ranking, RankingFormula, RankingItem, RankingMap, Side, MatchWithMetadata } from './types';
import { t } from './lang';

/**
Expand Down Expand Up @@ -73,8 +73,8 @@ export function findRoot(selector?: string): HTMLElement {
* @param matches The list of first round matches.
* @param nextMatches The list of second round matches.
*/
export function completeWithBlankMatches(bracketType: GroupType, matches: Match[], nextMatches?: Match[]): {
matches: (Match | null)[],
export function completeWithBlankMatches(bracketType: GroupType, matches: MatchWithMetadata[], nextMatches?: MatchWithMetadata[]): {
matches: (MatchWithMetadata | null)[],
fromToornament: boolean,
} {
if (!nextMatches)
Expand Down Expand Up @@ -233,10 +233,20 @@ function createRanking(rankingMap: RankingMap): RankingItem[] {
}

/**
* Indicates whether the input is a match or a match game.
* Indicates whether the input is a match.
*
* @param input A match or a match game.
*/
export function isMatch(input: Match | MatchGame): input is Match {
return 'child_count' in input;
}


/**
* Indicates whether the input is a match game.
*
* @param input A match or a match game.
*/
export function isMatchGame(input: Match | MatchGame): input is MatchGame {
return 'parent_id' in input;
return !isMatch(input);
}
1 change: 1 addition & 0 deletions src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"grand-final": "Winner of $t(abbreviations.loser-bracket) Final"
},
"match-label": {
"default": "Match {{matchNumber}}",
"winner-bracket": "$t(abbreviations.winner-bracket)",
"loser-bracket": "$t(abbreviations.loser-bracket)",
"standard-bracket": "$t(abbreviations.match)",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"grand-final": "Gagnant Finale $t(abbreviations.loser-bracket)"
},
"match-label": {
"default": "Match {{matchNumber}}",
"winner-bracket": "$t(abbreviations.winner-bracket)",
"loser-bracket": "$t(abbreviations.loser-bracket)",
"standard-bracket": "$t(abbreviations.match)",
Expand Down
5 changes: 4 additions & 1 deletion src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export function getFinalOriginHint(finalType: FinalType, roundNumber: number): O
* @param roundCount Count of rounds.
* @param matchLocation Location of the match.
*/
export function getMatchLabel(matchNumber: number, roundNumber: number, roundCount: number, matchLocation: GroupType): string {
export function getMatchLabel(matchNumber: number, roundNumber?: number, roundCount?: number, matchLocation?: GroupType): string {
if (roundNumber === undefined || roundCount === undefined || matchLocation === undefined)
return t('match-label.default', { matchNumber });

const matchPrefix = matchLocation === 'winner_bracket' ? t('match-label.winner-bracket') :
matchLocation === 'loser_bracket' ? t('match-label.loser-bracket') : t('match-label.standard-bracket');

Expand Down

0 comments on commit 2da6a57

Please sign in to comment.