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 8cbddc5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/game/detail/stats/stats.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
></ng-table>
</div>
</div>
<div *ngIf="game.gameVideoUrl" class="row">
<div *ngIf="game.gameVideoUrl && isBrowser" class="row">
<div class="col-md-12">
<vg-player>
<video [vgMedia]="media" #media id="replay" preload="auto" controls style="width: 100%">
Expand Down
11 changes: 10 additions & 1 deletion src/app/game/detail/stats/stats.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Input, OnInit } from "@angular/core";
import { Game, GamePlayer, ProfileCacheService, CivGame, MetadataCacheService } from "pydt-shared";
import { Utility } from "../../../shared/utility";
import { BrowserDataService } from "../../../shared/browser-data.service";

export interface TableColumn {
title: string;
Expand Down Expand Up @@ -28,12 +29,20 @@ export class GameDetailStatsComponent implements OnInit {
tableData: Array<unknown>;
games: CivGame[] = [];

constructor(private profileCache: ProfileCacheService, private metadataCache: MetadataCacheService) {}
constructor(
private profileCache: ProfileCacheService,
private metadataCache: MetadataCacheService,
private browserData: BrowserDataService,
) {}

get civGame(): CivGame {
return this.games.find(x => x.id === this.game.gameType);
}

get isBrowser() {
return this.browserData.isBrowser();
}

async ngOnInit(): Promise<void> {
this.games = (await this.metadataCache.getCivGameMetadata()).civGames;
if (this.civGame.turnTimerSupported) {
Expand Down
13 changes: 9 additions & 4 deletions src/app/game/detail/turns/turns.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export class GameDetailTurnsComponent implements OnInit {

this.profiles = await this.profileCache.getProfiles(this.humanPlayers.map(x => x.steamId));
await this.updateTable();

// Fire event to get angular to recognize it
window.dispatchEvent(new CustomEvent("DownloadTurn"));
}

async updateTable(page = 1): Promise<void> {
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 8cbddc5

Please sign in to comment.