Fix platform grid not showing for logged-in regular users

Two issues:
1. Race condition: me.php resolves before the platforms fetch, so
   showApp() runs with an empty CFG.platforms and the grid stays
   blank until the Promise.all resolves. Fixed by calling
   buildPlatforms() inside showApp() when platforms are already
   loaded, guaranteeing the grid renders when the app becomes visible.
2. Stale placeholder: 'links' platform (is_active=1) was polluting
   the grid with a "Platform Links coming..." card. Disabled in DB
   (is_active=0).

Also hardened buildPlatforms/buildCashoutPlatforms: null-guard on
selects, early return when CFG.platforms is empty, and clear select
options before re-populating to prevent duplicates on re-call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-06 10:29:27 +00:00
parent 8238db3026
commit 8c1332c0c6
+21 -8
View File
@@ -1317,7 +1317,10 @@ function showApp() {
var app = document.getElementById('main-app');
if (auth) auth.setAttribute('style', 'display:none');
if (app) app.setAttribute('style', 'display:block;min-height:100vh;');
console.log('showApp: auth hidden, app visible');
// Rebuild platform grid now that app is visible (covers race where me.php resolves before platforms fetch)
if (CFG.platforms && CFG.platforms.length) {
try { buildPlatforms(); buildCashoutPlatforms(); } catch(e) {}
}
try { updateUI(); } catch(e) { console.warn('updateUI err:', e); }
try { loadCashoutHistory(); } catch(e) { console.warn('cashout err:', e); }
try { pollChatBadge(); } catch(e) { console.warn('badge err:', e); }
@@ -1398,7 +1401,11 @@ async function refreshUser() {
// ─── PLATFORMS ─────────────────────────────────────────────
function buildPlatforms() {
document.getElementById('platform-grid').innerHTML = CFG.platforms.map(p => `
if (!CFG.platforms || !CFG.platforms.length) return;
const grid = document.getElementById('platform-grid');
if (grid) {
grid.innerHTML = CFG.platforms.map(p => `
<a href="${p.url}" target="_blank" class="platform-card" style="--p-color:${p.color}">
<div class="platform-img-wrap">
<img src="/assets/img/${p.id}.svg" alt="${p.name}" onerror="this.style.display='none'">
@@ -1406,16 +1413,22 @@ function buildPlatforms() {
<div class="platform-name">${p.name}</div>
<div class="play-btn">TAP TO PLAY →</div>
</a>`).join('');
}
// Also populate buy-platform select
const sel = document.getElementById('buy-platform');
CFG.platforms.forEach(p => {
const o = document.createElement('option');
o.value = p.id; o.textContent = p.name; sel.appendChild(o);
});
// Populate selects — clear dynamic options first to prevent duplicates on re-call
const buySel = document.getElementById('buy-platform');
if (buySel) {
while (buySel.options.length > 1) buySel.remove(1);
CFG.platforms.forEach(p => {
const o = document.createElement('option');
o.value = p.id; o.textContent = p.name; buySel.appendChild(o);
});
}
}
function buildCashoutPlatforms() {
const sel = document.getElementById('cashout-platform');
if (!sel) return;
while (sel.options.length > 1) sel.remove(1);
CFG.platforms.forEach(p => {
const o = document.createElement('option'); o.value = p.id; o.textContent = p.name; sel.appendChild(o);
});