Commit 7505311c authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: hide cancelled/stale tournaments + allow registration on draft status

- tournaments.php: exclude cancelled tournaments (neq.cancelled filter),
  hide completed tournaments older than 3 days
- hub.js: treat 'draft' status same as 'registration' — show register
  button, green status pill, include in "registration open" filter
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent cffab8c7
......@@ -16,7 +16,8 @@ if ($method === 'GET') {
if ($action === 'list') {
$tournaments = $db->get('el3ab_tournaments', [
'select' => 'id,name,game_key,format,time_control,status,max_players,swiss_rounds,rounds_total,starts_at,prize_pool_coins,entry_fee_coins',
'select' => 'id,name,game_key,format,time_control,status,max_players,swiss_rounds,rounds_total,starts_at,prize_pool_coins,entry_fee_coins,updated_at',
'status' => 'neq.cancelled',
'order' => 'created_at.desc',
'limit' => 50
]);
......@@ -25,6 +26,15 @@ if ($method === 'GET') {
jsonResponse(['tournaments' => []]);
}
$cutoff = date('c', strtotime('-3 days'));
$tournaments = array_values(array_filter($tournaments, function ($t) use ($cutoff) {
if ($t['status'] === 'completed') {
$endDate = $t['updated_at'] ?? $t['starts_at'] ?? '';
return $endDate > $cutoff;
}
return true;
}));
foreach ($tournaments as &$t) {
$regs = $db->get('tournament_registrations', [
'tournament_id' => 'eq.' . $t['id'],
......@@ -32,6 +42,7 @@ if ($method === 'GET') {
'status' => 'eq.registered'
]);
$t['player_count'] = is_array($regs) && !isset($regs['error']) ? count($regs) : 0;
unset($t['updated_at']);
}
jsonResponse(['tournaments' => $tournaments]);
......
......@@ -86,6 +86,8 @@ async function loadTournaments(el) {
if (activeFilter === 'my') {
tournaments = tournaments.filter(t => registeredIds.has(t.id));
} else if (activeFilter === 'registration') {
tournaments = tournaments.filter(t => t.status === 'registration' || t.status === 'draft');
} else if (activeFilter !== 'all') {
tournaments = tournaments.filter(t => t.status === activeFilter);
}
......@@ -154,7 +156,7 @@ async function loadTournaments(el) {
</div>
` : isRegistered ? `
<div style="font-size:11px;color:var(--success);font-weight:600;">${emoji('checkmark', '✓', 11)} ${t('tournament.joined')}</div>
` : tour.status === 'registration' ? `
` : (tour.status === 'registration' || tour.status === 'draft') ? `
<button class="register-btn" data-tid="${tour.id}" style="width:100%;background:var(--gold);border:none;border-radius:10px;padding:12px;color:#000;font-weight:700;font-size:13px;cursor:pointer;margin-top:4px;">${emoji('swords', '⚔️', 13)} ${t('tournament.register_now')}${tour.entry_fee_coins ? ' — ' + tour.entry_fee_coins + ' ' + t('common.coins') : ''}</button>
` : ''}
</div>
......@@ -233,7 +235,7 @@ async function loadTournaments(el) {
function getStatusColor(status) {
switch (status) {
case 'registration': return 'var(--success)';
case 'registration': case 'draft': return 'var(--success)';
case 'in_progress': return 'var(--gold)';
case 'completed': return 'var(--text-muted)';
default: return 'var(--blue)';
......@@ -242,10 +244,9 @@ function getStatusColor(status) {
function getStatusLabel(status) {
switch (status) {
case 'registration': return t('tournament.registration_open');
case 'registration': case 'draft': return t('tournament.registration_open');
case 'in_progress': return t('tournament.active');
case 'completed': return t('tournament.completed');
case 'draft': return t('tournament.coming_soon');
default: return status || t('tournament.upcoming');
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment