Skip to content

Commit

Permalink
get available turns from server
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosack committed Jun 28, 2023
1 parent da55fd2 commit b180471
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"ngx-clipboard": "^15.1.0",
"ngx-markdown": "^15.0.0",
"pako": "^2.1.0",
"pydt-shared": "^1.8.5",
"pydt-shared": "^1.8.6",
"remove-markdown": "^0.5.0",
"rollbar": "^2.26.0",
"rxjs": "^7.8.0",
Expand Down Expand Up @@ -102,4 +102,4 @@
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
}
}
}
21 changes: 4 additions & 17 deletions src/app/game/detail/turns/turns.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
SteamProfileMap,
MetadataCacheService,
CivGame,
GameTurn,
GamePlayer,
GameTurnListItem,
} from "pydt-shared";
import { Utility } from "../../../shared/utility";
import { Parser } from "json2csv";
Expand Down Expand Up @@ -121,23 +121,10 @@ export class GameDetailTurnsComponent implements OnInit {
window.location.href = resp.downloadUrl;
}

private createTableData(turns: GameTurn[], textOnly: boolean): unknown[] {
const canDownload = (turn: GameTurn) => {
if (!this.auth.getToken()) {
// Unauthenticated users can't download
return false;
}

// Only go back 20 turns since that's all PYDT keeps
if (turn.turn < (this.game.gameTurnRangeKey || 0) - 20) {
return false;
}

// Allow download if it's the end user's turn or if the game is finalized
return this.game.finalized || turn.playerSteamId === this.auth.getSteamProfile().steamid;
};
private createTableData(turns: GameTurnListItem[], textOnly: boolean): unknown[] {
const canDownload = (turn: GameTurnListItem) => this.auth.getToken() && turn.hasSave;

if (turns.some(x => canDownload(x)) && !this.tableColumns.some(x => x.name === "download")) {
if (turns.some(canDownload) && !this.tableColumns.some(x => x.name === "download")) {
this.tableColumns = [
...this.tableColumns,
{
Expand Down

0 comments on commit b180471

Please sign in to comment.