diff --git a/api_v1_user.php b/api_v1_user.php index f7f851c..c7468e3 100644 --- a/api_v1_user.php +++ b/api_v1_user.php @@ -1,4 +1,6 @@ prepare("UPDATE users SET username = ?, avatar_url = ?, dnd_mode = ?, sound_notifications = ?, theme = ? WHERE id = ?"); $stmt->execute([$username, $avatar_url, $dnd_mode, $sound_notifications, $theme, $user['id']]); - $_SESSION['username'] = $username; // Update session if stored (though getCurrentUser fetches from DB) - echo json_encode(['success' => true]); } catch (Exception $e) { echo json_encode(['success' => false, 'error' => $e->getMessage()]); diff --git a/assets/css/discord.css b/assets/css/discord.css index 65e45c8..f82ec99 100644 --- a/assets/css/discord.css +++ b/assets/css/discord.css @@ -79,6 +79,16 @@ border-color: #c7ccd1; } +[data-theme="dark"] .btn-outline-secondary { + color: #b5bac1; + border-color: #4e5058; +} + +[data-theme="dark"] .btn-outline-secondary:hover { + background-color: #4e5058; + color: #ffffff; +} + [data-theme="light"] .btn-check:checked + .btn-outline-secondary { background-color: var(--blurple) !important; border-color: var(--blurple) !important; diff --git a/assets/js/main.js b/assets/js/main.js index 37ad53b..42df985 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -2231,22 +2231,38 @@ document.addEventListener('DOMContentLoaded', () => { const saveSettingsBtn = document.getElementById('save-settings-btn'); saveSettingsBtn?.addEventListener('click', async () => { const form = document.getElementById('user-settings-form'); + if (!form) return; + const formData = new FormData(form); - const dndMode = document.getElementById('dnd-switch').checked ? '1' : '0'; - formData.append('dnd_mode', dndMode); - const theme = form.querySelector('input[name="theme"]:checked').value; + // Ensure switches are correctly sent as 1/0 + const dndMode = document.getElementById('dnd-switch')?.checked ? '1' : '0'; + const soundNotifications = document.getElementById('sound-switch')?.checked ? '1' : '0'; + formData.set('dnd_mode', dndMode); + formData.set('sound_notifications', soundNotifications); + + // Explicitly get theme to ensure it's captured + const themeInput = form.querySelector('input[name="theme"]:checked'); + const theme = themeInput ? themeInput.value : 'dark'; + formData.set('theme', theme); + + // Visual feedback document.body.setAttribute('data-theme', theme); - const resp = await fetch('api_v1_user.php', { - method: 'POST', - body: formData - }); - const result = await resp.json(); - if (result.success) { - location.reload(); - } else { - alert(result.error || 'Failed to save settings'); + try { + const resp = await fetch('api_v1_user.php?v=' + Date.now(), { + method: 'POST', + body: formData + }); + const result = await resp.json(); + if (result.success) { + window.location.href = window.location.pathname + window.location.search; + } else { + alert(result.error || 'Failed to save settings'); + } + } catch (e) { + console.error('Error saving settings:', e); + alert('Failed to save settings. Please check your connection.'); } }); diff --git a/index.php b/index.php index 0087a6f..75495d1 100644 --- a/index.php +++ b/index.php @@ -306,7 +306,7 @@ $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; } -
+