Skip to content

Commit

Permalink
create DownloadTurn event ahead of time
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosack committed Jun 28, 2023
1 parent 9fb3e66 commit 902bb71
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/app/game/detail/turns/turns.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export class GameDetailTurnsComponent implements OnInit {
private gameService: GameService,
private metadataCache: MetadataCacheService,
private auth: AuthService,
) {}
) {
// Fire custom event so it exists to bind to
window.dispatchEvent(new CustomEvent("DownloadTurn"));
}

get civGame(): CivGame {
return this.games.find(x => x.id === this.game.gameType);
Expand Down Expand Up @@ -115,10 +118,12 @@ export class GameDetailTurnsComponent implements OnInit {
}

@HostListener("window:DownloadTurn", ["$event.detail"])
public async downloadTurn(turn: number): Promise<void> {
const resp = await this.gameService.getTurnById(this.game.gameId, turn).toPromise();
public async downloadTurn(turn?: number): Promise<void> {
if (turn) {
const resp = await this.gameService.getTurnById(this.game.gameId, turn).toPromise();

window.location.href = resp.downloadUrl;
window.location.href = resp.downloadUrl;
}
}

private createTableData(turns: GameTurn[], textOnly: boolean): unknown[] {
Expand Down Expand Up @@ -165,7 +170,7 @@ export class GameDetailTurnsComponent implements OnInit {
timeTaken: timeTaken.toString(),
skipped: turn.skipped ? "Skipped!" : "",
download: canDownload(turn)
? `<a href='#' *ngIf="false" onClick="window.dispatchEvent(new CustomEvent('DownloadTurn', { detail: ${turn.turn} }));return false;">Download</a>`
? `<a href='#' onClick="window.dispatchEvent(new CustomEvent('DownloadTurn', { detail: ${turn.turn} }));return false;">Download</a>`
: "",
};
});
Expand Down

0 comments on commit 902bb71

Please sign in to comment.