refactor: przeniesienie konfiguracji kanału logów do dedykowanego modalu Ustawienia z wybierakiem per-serwer
This commit is contained in:
5 files changed
+269
-51
No files matched your search
+75
-34
@@ -16,8 +16,10 @@ let wsConnectedOnce = false;
|
||||
// DOM Elements
|
||||
const statusDot = document.getElementById('status-dot');
|
||||
const statusText = document.getElementById('status-text');
|
||||
const voiceSelect = document.getElementById('voice-channel-select');
|
||||
const textChannelSelect = document.getElementById('text-channel-select');
|
||||
const btnOpenSettings = document.getElementById('btn-open-settings');
|
||||
const btnCloseSettings = document.getElementById('btn-close-settings');
|
||||
const settingsModal = document.getElementById('settings-modal');
|
||||
const settingsGuildsList = document.getElementById('settings-guilds-list');
|
||||
const btnConnect = document.getElementById('btn-connect');
|
||||
const trackTitle = document.getElementById('track-title');
|
||||
const trackArtist = document.getElementById('track-artist');
|
||||
@@ -162,8 +164,14 @@ function bindEvents() {
|
||||
// Add Song Form
|
||||
addForm.addEventListener('submit', addTrack);
|
||||
|
||||
// Text Channel Select
|
||||
textChannelSelect.addEventListener('change', changeTextChannel);
|
||||
// Settings Modal Events
|
||||
if (btnOpenSettings) btnOpenSettings.addEventListener('click', openSettingsModal);
|
||||
if (btnCloseSettings) btnCloseSettings.addEventListener('click', closeSettingsModal);
|
||||
if (settingsModal) {
|
||||
settingsModal.addEventListener('click', (e) => {
|
||||
if (e.target === settingsModal) closeSettingsModal();
|
||||
});
|
||||
}
|
||||
|
||||
// Upload Events
|
||||
if (btnSelectFile && fileInput) {
|
||||
@@ -296,30 +304,9 @@ function updateUI(status) {
|
||||
}
|
||||
}
|
||||
|
||||
// Text selector population (only if select doesn't have focus/interaction)
|
||||
if (document.activeElement !== textChannelSelect) {
|
||||
const currentSelectedText = textChannelSelect.value;
|
||||
textChannelSelect.innerHTML = '<option value="" disabled>Wybierz kanał...</option>';
|
||||
|
||||
if (status.text_channels && status.text_channels.length > 0) {
|
||||
status.text_channels.forEach(channel => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = channel.channel_id;
|
||||
opt.textContent = `${channel.guild_name} - #${channel.channel_name}`;
|
||||
textChannelSelect.appendChild(opt);
|
||||
});
|
||||
|
||||
if (status.active_text_channel_id) {
|
||||
textChannelSelect.value = status.active_text_channel_id;
|
||||
} else if (currentSelectedText && status.text_channels.some(c => c.channel_id === currentSelectedText)) {
|
||||
textChannelSelect.value = currentSelectedText;
|
||||
}
|
||||
} else {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = "";
|
||||
opt.textContent = "Brak dostępnych kanałów";
|
||||
textChannelSelect.appendChild(opt);
|
||||
}
|
||||
// Settings Guilds Population
|
||||
if (status.guilds) {
|
||||
renderSettingsGuilds(status.guilds);
|
||||
}
|
||||
|
||||
// 2. Playback State
|
||||
@@ -753,19 +740,73 @@ async function setVolume(vol) {
|
||||
}
|
||||
}
|
||||
|
||||
// Change Text Notification Channel
|
||||
async function changeTextChannel() {
|
||||
const channelId = textChannelSelect.value;
|
||||
if (!channelId) return;
|
||||
// Settings Modal Functions
|
||||
function openSettingsModal() {
|
||||
if (settingsModal) settingsModal.style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeSettingsModal() {
|
||||
if (settingsModal) settingsModal.style.display = 'none';
|
||||
}
|
||||
|
||||
function renderSettingsGuilds(guilds) {
|
||||
if (!settingsGuildsList) return;
|
||||
|
||||
// Don't re-render if user is currently interacting with a select inside settings
|
||||
if (settingsModal && settingsModal.style.display !== 'none' && document.activeElement && document.activeElement.classList.contains('guild-log-select')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!guilds || guilds.length === 0) {
|
||||
settingsGuildsList.innerHTML = '<div class="empty-queue-message"><i data-lucide="server"></i><p>Brak serwerów Discord w pamięci bota.</p></div>';
|
||||
lucide.createIcons();
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
guilds.forEach(guild => {
|
||||
let optionsHtml = '';
|
||||
if (guild.text_channels && guild.text_channels.length > 0) {
|
||||
guild.text_channels.forEach(tc => {
|
||||
const isSelected = guild.active_notification_channel_id === tc.channel_id ? 'selected' : '';
|
||||
optionsHtml += `<option value="${tc.channel_id}" ${isSelected}>#${tc.channel_name}</option>`;
|
||||
});
|
||||
} else {
|
||||
optionsHtml = '<option value="" disabled>Brak kanałów tekstowych</option>';
|
||||
}
|
||||
|
||||
html += `
|
||||
<div class="guild-setting-row glass-card-subtle">
|
||||
<div class="guild-info">
|
||||
<div class="guild-icon"><i data-lucide="shield"></i></div>
|
||||
<div>
|
||||
<div class="guild-name">${guild.guild_name}</div>
|
||||
<div class="guild-id">ID: ${guild.guild_id}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="guild-control">
|
||||
<select class="premium-select guild-log-select" data-guild-id="${guild.guild_id}" onchange="saveGuildLogChannel('${guild.guild_id}', this.value)">
|
||||
<option value="">-- Brak / Domyślny --</option>
|
||||
${optionsHtml}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
settingsGuildsList.innerHTML = html;
|
||||
lucide.createIcons();
|
||||
}
|
||||
|
||||
async function saveGuildLogChannel(guildId, channelId) {
|
||||
try {
|
||||
const res = await fetch('/api/settings/text_channel', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ channel_id: channelId })
|
||||
body: JSON.stringify({ guild_id: guildId, channel_id: channelId || "" })
|
||||
});
|
||||
if (!res.ok) throw new Error('Settings change failed');
|
||||
showToast('Zapisano kanał powiadomień na Discordzie!', 'success');
|
||||
showToast('Zapisano kanał powiadomień dla serwera!', 'success');
|
||||
} catch (err) {
|
||||
showToast('Nie udało się zapisać kanału powiadomień', 'error');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user