-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display scores next to player names and add filters in Game Arc…
…hives page
- Loading branch information
Michal Wiraszka
committed
Aug 4, 2024
1 parent
0214a51
commit 5b99b41
Showing
14 changed files
with
533 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<div [id]="'pgn-viewer-' + index"></div> | ||
<div [id]="viewerId"></div> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,87 @@ | ||
import LichessPgnViewer from 'lichess-pgn-viewer'; | ||
|
||
import { DOCUMENT } from '@angular/common'; | ||
import { AfterViewInit, Component, Inject, Input } from '@angular/core'; | ||
import { AfterViewInit, Component, Inject, Input, OnInit } from '@angular/core'; | ||
|
||
import { getPlayerName, getScore } from '@app/utils/pgn-utils'; | ||
|
||
@Component({ | ||
selector: 'lcc-pgn-viewer', | ||
templateUrl: './pgn-viewer.component.html', | ||
styleUrls: ['./pgn-viewer.component.scss'], | ||
}) | ||
export class PgnViewerComponent implements AfterViewInit { | ||
@Input() pgn?: string; | ||
@Input() index!: number; | ||
export class PgnViewerComponent implements OnInit, AfterViewInit { | ||
viewerId!: string; | ||
|
||
container: HTMLElement | null = null; | ||
@Input() index!: number; | ||
@Input() label!: string; | ||
@Input() pgn!: string; | ||
|
||
constructor(@Inject(DOCUMENT) private _document: Document) {} | ||
|
||
ngOnInit(): void { | ||
this.viewerId = `pgn-viewer--${this.label}--${this.index}`; | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.container = this._document.getElementById(`pgn-viewer-${this.index}`); | ||
if (this.container) { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _ = LichessPgnViewer(this.container, { pgn: this.pgn }); | ||
const container = this._document.getElementById(this.viewerId); | ||
|
||
if (container) { | ||
const _ = LichessPgnViewer(container, { | ||
classes: this.viewerId, // Required for query selectors below | ||
initialPly: 'last', | ||
orientation: 'white', | ||
pgn: this.pgn, | ||
showClocks: false, | ||
}); | ||
|
||
const whiteName = getPlayerName(this.pgn, 'White'); | ||
if (!whiteName) { | ||
console.error( | ||
'[LCC] A game with no defined White player was found: \n', | ||
this.pgn, | ||
); | ||
return; | ||
} | ||
|
||
const blackName = getPlayerName(this.pgn, 'Black'); | ||
if (!blackName) { | ||
console.error( | ||
'[LCC] A game with no defined Black player was found: \n', | ||
this.pgn, | ||
); | ||
return; | ||
} | ||
|
||
const whiteScore = getScore(this.pgn, 'White'); | ||
if (!whiteScore) { | ||
console.error( | ||
'[LCC] A game with no valid score for White was found: \n', | ||
this.pgn, | ||
); | ||
return; | ||
} | ||
|
||
const blackScore = getScore(this.pgn, 'Black'); | ||
if (!blackScore) { | ||
console.error( | ||
'[LCC] A game with no valid score for Black was found: \n', | ||
this.pgn, | ||
); | ||
return; | ||
} | ||
|
||
const whitePlayerElement = this._document.querySelector( | ||
`.${this.viewerId} .lpv__player--bottom > .lpv__player__person`, | ||
); | ||
const blackPlayerElement = this._document.querySelector( | ||
`.${this.viewerId} .lpv__player--top > .lpv__player__person`, | ||
); | ||
|
||
whitePlayerElement?.setAttribute('data-name', whiteName); | ||
whitePlayerElement?.setAttribute('data-score', whiteScore); | ||
|
||
blackPlayerElement?.setAttribute('data-name', blackName); | ||
blackPlayerElement?.setAttribute('data-score', blackScore); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.