/* Dashboard Preference Functions */ // Navigate to appearance quiz (default) in edit mode function editAppearancePreferences() { window.location.href = 'customizer.html?edit=true'; } // Navigate to story quiz in edit mode function editStoryPreferences() { window.location.href = 'customizer.html?quiz=story&edit=true'; } // Legacy function for backwards compatibility function editPreferences() { // Default to appearance preferences editAppearancePreferences(); } // Load and display current preferences in dashboard async function loadDashboardPreferences() { if (!window.supabase) { setTimeout(loadDashboardPreferences, 100); return; } try { const { data: { session } } = await supabase.auth.getSession(); if (!session || !session.user) { console.log('No user session found'); return; } const userId = session.user.id; // Load appearance preferences const { data: appearanceData, error: appearanceError } = await supabase .from('appearance_preferences') .select('*') .eq('user_id', userId) .order('created_at', { ascending: false }) .limit(1); if (appearanceError) { console.error('Error loading appearance preferences:', appearanceError); } else if (appearanceData && appearanceData.length > 0) { displayAppearancePreferences(appearanceData[0]); } // Load story preferences (including legacy data without quiz_type) console.log('🔍 Loading story preferences for user:', userId); const { data: storyData, error: storyError } = await supabase .from('user_preferences') .select('*') .eq('user_id', userId) .or('quiz_type.eq.story,quiz_type.is.null') .order('created_at', { ascending: false }) .limit(1); console.log('📊 Story query result:', { data: storyData, error: storyError }); if (storyError) { console.error('Error loading story preferences:', storyError); } else if (storyData && storyData.length > 0) { console.log('✅ Found story data, displaying:', storyData[0]); displayStoryPreferences(storyData[0]); } else { console.log('❌ No story preferences found for user'); } } catch (error) { console.error('Error loading dashboard preferences:', error); } } // Display appearance preferences in dashboard function displayAppearancePreferences(preferences) { const container = document.getElementById('currentAppearancePreferences'); if (!container) return; const eyeColorMap = { 'braun': 'Braun', 'blau': 'Blau', 'gruen': 'Grün', 'grau': 'Grau', 'bunt': 'Bunt', 'andere': 'Andere' }; const hairColorMap = { 'blond': 'Blond', 'braun': 'Braun', 'schwarz': 'Schwarz', 'rot': 'Rot/Rothaarig', 'grau': 'Grau', 'bunt': 'Bunt', 'andere': 'Andere' }; const hairLengthMap = { 'kurz': 'Kurz', 'mittel': 'Mittel', 'lang': 'Lang' }; container.innerHTML = `