feat: move history, export import fixed, timer added

This commit is contained in:
shahdlala66
2026-04-22 13:05:09 +02:00
parent a59e2a023b
commit 5951257c99
7 changed files with 628 additions and 214 deletions
@@ -18,8 +18,12 @@ export class WelcomeComponent {
errorMessage = '';
showDifficultySelector = false;
showJoinGameForm = false;
showImportGameForm = false;
gameIdInput = '';
joiningGame = false;
importing = false;
importMode: 'fen' | 'pgn' = 'fen';
importText = '';
constructor(
private readonly router: Router,
@@ -81,16 +85,60 @@ export class WelcomeComponent {
toggleDifficultySelector(): void {
this.showDifficultySelector = !this.showDifficultySelector;
this.showJoinGameForm = false;
this.showImportGameForm = false;
this.errorMessage = '';
}
toggleJoinGameForm(): void {
this.showJoinGameForm = !this.showJoinGameForm;
this.showDifficultySelector = false;
this.showImportGameForm = false;
this.errorMessage = '';
this.gameIdInput = '';
}
toggleImportGameForm(): void {
this.showImportGameForm = !this.showImportGameForm;
this.showDifficultySelector = false;
this.showJoinGameForm = false;
this.errorMessage = '';
if (!this.showImportGameForm) {
this.importText = '';
this.importMode = 'fen';
}
}
setImportMode(mode: 'fen' | 'pgn'): void {
this.importMode = mode;
this.errorMessage = '';
}
submitImportedGame(): void {
const trimmedImport = this.importText.trim();
if (this.importing || !trimmedImport) {
return;
}
this.errorMessage = '';
this.importing = true;
const importRequest =
this.importMode === 'fen' ? this.gameApi.importFen(trimmedImport) : this.gameApi.importPgn(trimmedImport);
importRequest.pipe(finalize(() => (this.importing = false))).subscribe({
next: (game) => {
this.importText = '';
this.showImportGameForm = false;
void this.router.navigate(['/game', game.gameId]);
},
error: (error) => {
const defaultMessage = this.importMode === 'fen' ? 'Unable to import FEN.' : 'Unable to import PGN.';
this.errorMessage = getErrorMessage(error, defaultMessage);
}
});
}
joinGame(): void {
if (this.joiningGame || !this.gameIdInput.trim()) {
return;