feat: Restaurar y mejorar la lógica de manejo de sesiones y estado, incluyendo la verificación de SID y el almacenamiento de estado

This commit is contained in:
Shni
2025-10-15 03:53:35 -05:00
parent 75b0305261
commit 02db391bfe
3 changed files with 105 additions and 80 deletions

View File

@@ -22,23 +22,30 @@
<svg class="w-3 h-3 text-white/80" viewBox="0 0 20 20" fill="none"><path d="M6 8l4 4 4-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg>
</button>
<div id="miniGuildList" class="origin-top-left absolute top-full left-0 mt-2 w-56 bg-white/80 backdrop-blur-md rounded-lg p-1 hidden transition-transform duration-150 z-50" style="max-height:18rem; overflow:auto; background-color: rgba(12,15,18,0.92);">
<% if (guilds && guilds.length) { %>
<% const withBot = guilds.filter(g=> g.botInGuild !== false); const withoutBot = guilds.filter(g=> g.botInGuild === false); %>
<% if (guilds && guilds.length) { %>
<% const withBot = guilds.filter(g=> g.botInGuild === true); const withoutBot = guilds.filter(g=> g.botInGuild !== true); %>
<% withBot.forEach(g => { %>
<div class="p-1 rounded-md hover:bg-white/5 cursor-pointer text-white guild-item flex items-center gap-3" data-id="<%= g.id %>" data-bot="1" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<div onclick="location.href='/dashboard/<%= g.id %>/overview'" role="button" tabindex="0" class="p-1 rounded-md hover:bg-white/5 cursor-pointer text-white guild-item flex items-center gap-3" data-id="<%= g.id %>" data-bot="1" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<% if (g.icon) { %>
<img src="https://cdn.discordapp.com/icons/<%= g.id %>/<%= g.icon %>.webp" class="w-5 h-5 rounded-full" alt="icon">
<% } else { %>
<div class="w-5 h-5 rounded-full bg-white/8 flex items-center justify-center text-xs text-white">S</div>
<% } %>
<div class="flex-1 text-sm truncate pl-1"><%= g.name %></div>
<div class="flex-1 text-sm truncate pl-1">
<%= g.name %>
<% if (g.botInGuild === true) { %>
<span class="ml-2 text-xs text-emerald-300">(Bot)</span>
<% } else { %>
<span class="ml-2 text-xs text-sky-300">(Invitar)</span>
<% } %>
</div>
<!-- invite button removed from inline list; rows without bot are dimmed and clicking them opens the invite -->
</div>
<% }) %>
<% if (withoutBot && withoutBot.length) { %>
<div class="border-t border-white/6 my-1"></div>
<% withoutBot.forEach(g => { %>
<div class="p-1 rounded-md hover:bg-white/5 cursor-pointer text-white guild-item flex items-center gap-3 opacity-60" data-id="<%= g.id %>" data-bot="0" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<div onclick="window.open('https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>', '_blank', 'noopener')" role="button" tabindex="0" class="p-1 rounded-md hover:bg-white/5 cursor-pointer text-white guild-item flex items-center gap-3 opacity-60" data-id="<%= g.id %>" data-bot="0" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<% if (g.icon) { %>
<img src="https://cdn.discordapp.com/icons/<%= g.id %>/<%= g.icon %>.webp" class="w-5 h-5 rounded-full" alt="icon">
<% } else { %>
@@ -130,25 +137,26 @@
openDropdown(btn, list);
}
});
Array.from(list.querySelectorAll('.guild-item')).forEach(it=>{
it.addEventListener('click', ()=>{
const id = it.getAttribute('data-id');
const bot = it.getAttribute('data-bot');
const invite = it.getAttribute('data-invite');
if (bot === '0' && invite) {
// open invite in a new tab
window.open(invite, '_blank', 'noopener');
return;
}
if (id) window.location.href = `/dashboard/${id}/overview`;
});
// keyboard activation (Enter / Space)
it.addEventListener('keydown', (ev)=>{
if (ev.key === 'Enter' || ev.key === ' ') {
ev.preventDefault();
it.click();
}
});
// Use event delegation on the list so clicks on children are handled reliably
list.addEventListener('click', (e)=>{
let el = e.target;
while (el && !el.dataset?.id && el !== list) el = el.parentElement;
if (!el || el === list) return;
const id = el.getAttribute('data-id');
const bot = el.getAttribute('data-bot');
const invite = el.getAttribute('data-invite');
const isDim = el.classList && el.classList.contains('opacity-60');
if (bot === '1') {
closeDropdown(btn, list);
window.location.href = `/dashboard/${id}/overview`;
return;
}
// if not explicitly '1', treat as missing and open invite if available
if ((bot === '0' || isDim) && invite) {
window.open(invite, '_blank', 'noopener');
closeDropdown(btn, list);
return;
}
});
}
if (userBtn && userMenu) {
@@ -211,21 +219,27 @@
</div>
<div id="mobileGuildList" class="space-y-2">
<% if (guilds && guilds.length) { %>
<% const withBot = guilds.filter(g=> g.botInGuild !== false); const withoutBot = guilds.filter(g=> g.botInGuild === false); %>
<% const withBot = guilds.filter(g=> g.botInGuild === true); const withoutBot = guilds.filter(g=> g.botInGuild !== true); %>
<% withBot.forEach(g => { %>
<div class="flex items-center gap-3 p-2 rounded-md hover:bg-white/5 cursor-pointer" data-id="<%= g.id %>" data-bot="1" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<div onclick="location.href='/dashboard/<%= g.id %>/overview'" role="button" tabindex="0" class="flex items-center gap-3 p-2 rounded-md hover:bg-white/5 cursor-pointer" data-id="<%= g.id %>" data-bot="1" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<% if (g.icon) { %>
<img src="https://cdn.discordapp.com/icons/<%= g.id %>/<%= g.icon %>.webp" class="w-8 h-8 rounded-full" alt="icon">
<% } else { %>
<div class="w-8 h-8 rounded-full bg-white/8"></div>
<% } %>
<div class="text-white"><%= g.name %></div>
<div class="text-white"><%= g.name %>
<% if (g.botInGuild === true) { %>
<span class="ml-2 text-xs text-emerald-300">(Bot)</span>
<% } else { %>
<span class="ml-2 text-xs text-sky-300">(Invitar)</span>
<% } %>
</div>
</div>
<% }) %>
<% if (withoutBot && withoutBot.length) { %>
<div class="border-t border-white/6 mt-2 pt-2"></div>
<% withoutBot.forEach(g => { %>
<div class="flex items-center gap-3 p-2 rounded-md hover:bg-white/5 cursor-pointer opacity-60" data-id="<%= g.id %>" data-bot="0" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<div onclick="window.open('https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>', '_blank', 'noopener')" role="button" tabindex="0" class="flex items-center gap-3 p-2 rounded-md hover:bg-white/5 cursor-pointer opacity-60" data-id="<%= g.id %>" data-bot="0" data-invite="https://discord.com/oauth2/authorize?client_id=991062751633883136&permissions=2416176272&integration_type=0&scope=bot&guild_id=<%= g.id %>">
<% if (g.icon) { %>
<img src="https://cdn.discordapp.com/icons/<%= g.id %>/<%= g.icon %>.webp" class="w-8 h-8 rounded-full" alt="icon">
<% } else { %>
@@ -289,10 +303,11 @@
let el = e.target;
while (el && !el.dataset?.id) el = el.parentElement;
if (el && el.dataset && el.dataset.id) {
const bot = el.getAttribute('data-bot');
const invite = el.getAttribute('data-invite');
if (bot === '0' && invite) { window.open(invite, '_blank', 'noopener'); return; }
window.location.href = `/dashboard/${el.dataset.id}/overview`;
const bot = el.getAttribute('data-bot');
const invite = el.getAttribute('data-invite');
const isDim = el.classList && el.classList.contains('opacity-60');
if (bot === '1') { window.location.href = `/dashboard/${el.dataset.id}/overview`; return; }
if ((bot === '0' || isDim) && invite) { window.open(invite, '_blank', 'noopener'); return; }
}
});