Skip to content

Commit

Permalink
simplify the js by sending everything always
Browse files Browse the repository at this point in the history
This also means when you e.g. create a new game, the url will contain the version and goal ids of the old game. But we properly validate this in the OnGet anyway, as we should.
  • Loading branch information
Masterjun3 committed Aug 22, 2024
1 parent f1e03d0 commit cbb2ddc
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions TASVideos/wwwroot/js/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,32 @@ function enableCataloging() {
}

document.getElementById('create-version')?.addEventListener('click', function () {
const returnUrlQueryModified = new URLSearchParams();
returnUrlQueryModified.set('SystemId', systemModel.value);
returnUrlQueryModified.set('GameId', gameModel.value);
document.location = `/Games/${gameModel.value}/Versions/Edit?SystemId=${systemModel.value}&returnUrl=${encodeURIComponent(returnUrlPath + '?' + returnUrlQueryModified.toString())}`;
document.location = `/Games/${gameModel.value}/Versions/Edit?SystemId=${systemModel.value}&returnUrl=${generateCurrentReturnUrl() }`;
});

document.getElementById('create-game')?.addEventListener('click', function () {
const returnUrlQueryModified = new URLSearchParams();
returnUrlQueryModified.set('SystemId', systemModel.value);
if (gameModel.value) {
returnUrlQueryModified.set('GameId', gameModel.value);
}
document.location = `/Games/Edit?returnUrl=${encodeURIComponent(returnUrlPath + '?' + returnUrlQueryModified.toString())}`;
document.location = `/Games/Edit?returnUrl=${generateCurrentReturnUrl() }`;
});

gameGoalBtn?.addEventListener('click', function () {
document.location = `/Games/${gameModel.value}/Goals/List?returnUrl=${generateCurrentReturnUrl()}`;
});

function generateCurrentReturnUrl() {
const returnUrlQueryModified = new URLSearchParams();
returnUrlQueryModified.set('SystemId', systemModel.value);
returnUrlQueryModified.set('GameId', gameModel.value);
if (systemModel.value) {
returnUrlQueryModified.set('SystemId', systemModel.value);
}
if (gameModel.value) {
returnUrlQueryModified.set('GameId', gameModel.value);
}
if (versionModel.value) {
returnUrlQueryModified.set('GameVersionId', versionModel.value);
}
if (gameGoalModel.value) {
returnUrlQueryModified.set('GameGoalId', gameGoalModel.value);
}
document.location = `/Games/${gameModel.value}/Goals/List?returnUrl=${encodeURIComponent(returnUrlPath + '?' + returnUrlQueryModified.toString())}`;
});

return encodeURIComponent(returnUrlPath + '?' + returnUrlQueryModified.toString());
}
}

0 comments on commit cbb2ddc

Please sign in to comment.