add game ID filter to /games search page (#1260)
This commit is contained in:
@@ -280,6 +280,10 @@
|
||||
<div class="autocomplete-list" id="squadronDropdown"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="search-field" style="flex: 1.2;">
|
||||
<label>Game ID</label>
|
||||
<input type="text" class="search-input" id="gameIdInput" placeholder="e.g. 3a7f…" autocomplete="off" spellcheck="false" style="font-family: monospace; letter-spacing: 0.02em;">
|
||||
</div>
|
||||
<div class="search-field">
|
||||
<label><%= t('games.filterByMap') %></label>
|
||||
<select class="search-select" id="mapSelect">
|
||||
@@ -518,6 +522,18 @@
|
||||
});
|
||||
|
||||
async function searchGames() {
|
||||
const gameId = document.getElementById('gameIdInput').value.trim();
|
||||
if (gameId) {
|
||||
if (!/^[0-9a-fA-F]+$/.test(gameId)) {
|
||||
document.getElementById('gameIdInput').style.borderColor = 'rgba(255, 100, 100, 0.6)';
|
||||
document.getElementById('gameIdInput').focus();
|
||||
return;
|
||||
}
|
||||
window.location.href = `/games/${gameId}`;
|
||||
return;
|
||||
}
|
||||
document.getElementById('gameIdInput').style.borderColor = '';
|
||||
|
||||
const player = document.getElementById('playerInput').value.trim();
|
||||
const map = document.getElementById('mapSelect').value;
|
||||
const squadron = selectedSquadronShort || document.getElementById('squadronInput').value.trim();
|
||||
@@ -586,10 +602,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('gameIdInput').addEventListener('input', function() {
|
||||
this.style.borderColor = '';
|
||||
});
|
||||
document.getElementById('gameIdInput').addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Enter') { e.preventDefault(); searchGames(); }
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
await Promise.all([loadMaps(), loadLeaderboardData()]);
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.get('game_id')) {
|
||||
window.location.href = `/games/${params.get('game_id')}`;
|
||||
return;
|
||||
}
|
||||
if (params.get('player')) {
|
||||
document.getElementById('playerInput').value = params.get('player');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user