Fix: Games and Game page save and navigation.

This commit is contained in:
2026-02-10 19:21:22 +00:00
parent 81fdfffbe5
commit 29ddd1ded0
7 changed files with 86 additions and 95 deletions

View File

@@ -438,7 +438,7 @@ export default class PageMtgGame extends TableBasePage {
const latestRoundId = PageMtgGame.getLatestRoundId();
const damageIndex = damageRecords.findIndex(damageRecord => (
damage[attrRoundId] == latestRoundId
damageRecord[attrRoundId] == latestRoundId
&& damageRecord[attrPlayerId] == playerId
&& damageRecord[attrReceivedFromCommanderPlayerId] == sourceId
));
@@ -616,18 +616,18 @@ export default class PageMtgGame extends TableBasePage {
}
async saveGame() {
/*
const gameState = {
[flagPlayer]: players
, [flagRound]: rounds
, [flagDamage]: damageRecords
};
/*
if (gameState[flagPlayer].length > 0) {
localStorage.setItem(`mtgGame_${gameId}`, JSON.stringify(gameState));
PageMtgGame.showSaveIndicator();
}
*/
const comment = 'Save players';
const comment = 'Save player damage';
const self = this;
API.saveGameRoundPlayerDamages(rounds, damageRecords, null, comment)
.then(data => {

View File

@@ -17,13 +17,13 @@ export default class PageMtgGames extends TableBasePage {
this.hookupTcgGames();
}
hookupTcgGames() {
PageMtgGames.initGamesPage();
this.initGamesPage();
}
static initGamesPage() {
initGamesPage() {
// Initialize form submission
const newGameForm = document.getElementById('newGameForm');
if (newGameForm) {
newGameForm.addEventListener('submit', PageMtgGames.handleNewGameSubmit);
newGameForm.addEventListener('submit', this.handleNewGameSubmit.bind(this)); // () => { this.handleNewGameSubmit.bind(this); });
}
// Initialize filter form
@@ -92,7 +92,7 @@ export default class PageMtgGames extends TableBasePage {
}
}
}
static async handleNewGameSubmit(e) {
async handleNewGameSubmit(e) {
e.preventDefault();
const form = e.target;
@@ -119,6 +119,7 @@ export default class PageMtgGames extends TableBasePage {
const games = [gameData];
const comment = 'Create new game';
debugger;
// const self = this;
API.saveGame(games, form, comment)
.then(data => {
if (data[flagStatus] == flagSuccess) {
@@ -126,7 +127,11 @@ export default class PageMtgGames extends TableBasePage {
Utils.consoleLogIfNotProductionEnvironment('Records saved!');
Utils.consoleLogIfNotProductionEnvironment('Data received:', data);
}
this.callFilterTableContent(gameData.game_id);
// this.callFilterTableContent(data[attrGameId]); // gameData.game_id
const gamePageHash = `${hashPageGame}/${data[attrGameId]}`;
let filtersJson = {};
this.leave();
API.goToHash(gamePageHash, filtersJson);
}
else {
Utils.consoleLogIfNotProductionEnvironment("error: " + data[flagMessage]);
@@ -144,13 +149,6 @@ export default class PageMtgGames extends TableBasePage {
});
}
callFilterTableContent(gameId) {
const gamePageHash = `${hashPageGame}/${gameId}`;
let filtersJson = {};
Utils.consoleLogIfNotProductionEnvironment("callFilterTableContent");
this.leave();
API.goToHash(gamePageHash, filtersJson);
}
static handleFilterSubmit(e) {
// Let the form submit normally - it will reload with query params
// You can add client-side filtering here if needed