🔧 Fix settings modal: Load current user preferences
- Added show_in_leaderboard to user-player API response - Improved loadSettings() function with better error handling - Added console logging for debugging - Settings modal now shows current user preference instead of always 'off' - Fixed dependency on currentPlayerId (now uses currentUser.id directly)
This commit is contained in:
@@ -952,21 +952,28 @@ function showSettings() {
|
|||||||
|
|
||||||
async function loadSettings() {
|
async function loadSettings() {
|
||||||
try {
|
try {
|
||||||
if (!currentPlayerId) {
|
if (!currentUser || !currentUser.id) {
|
||||||
console.error('No player ID available');
|
console.error('No user ID available');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load current player settings
|
// Load current player settings using user ID
|
||||||
const response = await fetch(`/api/v1/public/user-player/${currentUser.id}`);
|
const response = await fetch(`/api/v1/public/user-player/${currentUser.id}`);
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
if (result.success && result.data) {
|
if (result.success && result.data) {
|
||||||
const showInLeaderboard = result.data.show_in_leaderboard || false;
|
const showInLeaderboard = result.data.show_in_leaderboard || false;
|
||||||
document.getElementById('showInLeaderboard').checked = showInLeaderboard;
|
document.getElementById('showInLeaderboard').checked = showInLeaderboard;
|
||||||
|
console.log('Loaded settings - showInLeaderboard:', showInLeaderboard);
|
||||||
|
} else {
|
||||||
|
console.error('Failed to load player settings:', result.message);
|
||||||
|
// Set default to false if loading fails
|
||||||
|
document.getElementById('showInLeaderboard').checked = false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading settings:', error);
|
console.error('Error loading settings:', error);
|
||||||
|
// Set default to false if loading fails
|
||||||
|
document.getElementById('showInLeaderboard').checked = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1256,7 +1256,7 @@ router.get('/v1/public/user-player/:supabase_user_id', async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.query(
|
const result = await pool.query(
|
||||||
'SELECT id, firstname, lastname, birthdate, rfiduid FROM players WHERE supabase_user_id = $1',
|
'SELECT id, firstname, lastname, birthdate, rfiduid, show_in_leaderboard FROM players WHERE supabase_user_id = $1',
|
||||||
[supabase_user_id]
|
[supabase_user_id]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user