From b059fe1de0d2182c5ac1f934483e918961ee39a4 Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 16 Jul 2025 22:53:01 +0900 Subject: [PATCH] fix comment, rm console.log --- my-blog/static/js/ask-ai.js | 26 ---------- my-blog/static/js/theme.js | 3 +- oauth/.env.production | 2 +- oauth/src/components/RecordTabs.jsx | 78 +++++++++++++++++++++++------ oauth/src/hooks/useAdminData.js | 41 +++++++++++---- oauth/src/hooks/useUserData.js | 20 ++++---- oauth/src/utils/logger.js | 6 +-- 7 files changed, 109 insertions(+), 67 deletions(-) diff --git a/my-blog/static/js/ask-ai.js b/my-blog/static/js/ask-ai.js index ced9614..6b06687 100644 --- a/my-blog/static/js/ask-ai.js +++ b/my-blog/static/js/ask-ai.js @@ -12,14 +12,12 @@ const OAUTH_COLLECTION = window.OAUTH_CONFIG?.collection || 'ai.syui.log'; // Listen for AI profile data from OAuth app window.addEventListener('aiProfileLoaded', function(event) { - console.log('AI profile received from OAuth app:', event.detail); aiProfileData = event.detail; updateAskAIButton(); }); // Check if AI profile data is already available if (window.aiProfileData) { - console.log('AI profile already available:', window.aiProfileData); aiProfileData = window.aiProfileData; } @@ -30,11 +28,9 @@ function toggleAskAI() { panel.style.display = isVisible ? 'none' : 'block'; if (!isVisible) { - console.log('Ask AI panel opened'); // If AI profile data is already available, show introduction immediately if (aiProfileData) { - console.log('AI profile data available - showing introduction immediately'); // Quick check for authentication const userSections = document.querySelectorAll('.user-section'); const isAuthenticated = userSections.length > 0; @@ -45,17 +41,13 @@ function toggleAskAI() { // For production fallback - if OAuth app fails to load, show profiles const isProd = window.location.hostname !== 'localhost' && !window.location.hostname.includes('preview'); if (isProd) { - console.log('Production environment detected - using fallback profile display'); // Shorter timeout for production setTimeout(() => { const userSections = document.querySelectorAll('.user-section'); - console.log('Production check - user sections:', userSections.length); if (userSections.length === 0) { - console.log('No user sections found in production - showing profiles directly'); handleAuthenticationStatus(false); } else { - console.log('User sections found in production - showing authenticated UI'); handleAuthenticationStatus(true); } }, 300); @@ -71,19 +63,14 @@ function checkAuthenticationStatus() { const maxChecks = 10; const checkForAuth = () => { - console.log(`Auth check attempt ${checkCount + 1}/${maxChecks}`); const userSections = document.querySelectorAll('.user-section'); const authButtons = document.querySelectorAll('[data-auth-status]'); const oauthContainers = document.querySelectorAll('#oauth-container'); - console.log('User sections found:', userSections.length); - console.log('Auth buttons found:', authButtons.length); - console.log('OAuth containers found:', oauthContainers.length); const isAuthenticated = userSections.length > 0; if (isAuthenticated || checkCount >= maxChecks - 1) { - console.log('Final auth status:', isAuthenticated); handleAuthenticationStatus(isAuthenticated); } else { checkCount++; @@ -95,14 +82,12 @@ function checkAuthenticationStatus() { } function handleAuthenticationStatus(isAuthenticated) { - console.log('Handling auth status:', isAuthenticated); // Always hide loading first document.getElementById('authCheck').style.display = 'none'; if (isAuthenticated) { // User is authenticated - show Ask AI UI - console.log('User authenticated - showing AI chat interface'); document.getElementById('chatForm').style.display = 'block'; document.getElementById('chatHistory').style.display = 'block'; @@ -127,7 +112,6 @@ function handleAuthenticationStatus(isAuthenticated) { }, 50); } else { // User not authenticated - show AI introduction directly if profile available - console.log('User not authenticated - showing AI introduction'); document.getElementById('chatForm').style.display = 'none'; document.getElementById('chatHistory').style.display = 'block'; @@ -154,18 +138,15 @@ async function loadAndShowProfiles() { } const data = await response.json(); - console.log('Fetched records:', data.records); // Filter only profile records and sort const profileRecords = (data.records || []).filter(record => record.value.type === 'profile'); - console.log('Profile records:', profileRecords); const profiles = profileRecords.sort((a, b) => { if (a.value.profileType === 'admin' && b.value.profileType !== 'admin') return -1; if (a.value.profileType !== 'admin' && b.value.profileType === 'admin') return 1; return 0; }); - console.log('Sorted profiles:', profiles); // Clear loading message chatHistory.innerHTML = ''; @@ -201,7 +182,6 @@ async function loadAndShowProfiles() { } } catch (error) { - console.error('Error loading profiles:', error); chatHistory.innerHTML = '
Failed to load profiles. Please try again later.
'; } } @@ -230,7 +210,6 @@ function askQuestion() { })); } catch (error) { - console.error('Failed to ask question:', error); showErrorMessage('Sorry, I encountered an error. Please try again.'); } finally { askButton.disabled = false; @@ -402,7 +381,6 @@ function handleAIResponse(responseData) { const aiProfile = responseData.aiProfile; if (!aiProfile || !aiProfile.handle || !aiProfile.displayName) { - console.error('AI profile data is missing'); return; } @@ -444,7 +422,6 @@ function setupAskAIEventListeners() { // Listen for AI profile updates from OAuth app window.addEventListener('aiProfileLoaded', function(event) { aiProfileData = event.detail; - console.log('AI profile loaded:', aiProfileData); updateAskAIButton(); }); @@ -456,7 +433,6 @@ function setupAskAIEventListeners() { // Listen for OAuth callback completion from iframe window.addEventListener('message', function(event) { if (event.data.type === 'oauth_success') { - console.log('Received OAuth success message:', event.data); // Close any OAuth popups/iframes const oauthFrame = document.getElementById('oauth-frame'); @@ -505,7 +481,6 @@ function setupAskAIEventListeners() { // Initialize Ask AI when DOM is loaded document.addEventListener('DOMContentLoaded', function() { setupAskAIEventListeners(); - console.log('Ask AI initialized successfully'); // Also listen for OAuth app load completion const observer = new MutationObserver(function(mutations) { @@ -522,7 +497,6 @@ document.addEventListener('DOMContentLoaded', function() { ); if (userSectionAdded || userSectionRemoved) { - console.log('User section status changed'); // Update Ask AI panel if it's visible const panel = document.getElementById('askAiPanel'); if (panel && panel.style.display !== 'none') { diff --git a/my-blog/static/js/theme.js b/my-blog/static/js/theme.js index 108587e..bed15d5 100644 --- a/my-blog/static/js/theme.js +++ b/my-blog/static/js/theme.js @@ -84,11 +84,10 @@ class Theme { setupLogoAnimations() { // Pure CSS animations are handled by the svg-animation-package.css // This method is reserved for any future JavaScript-based enhancements - console.log('Logo animations initialized (CSS-based)'); } } // Initialize theme when DOM is loaded document.addEventListener('DOMContentLoaded', () => { new Theme(); -}); \ No newline at end of file +}); diff --git a/oauth/.env.production b/oauth/.env.production index 1a90551..58c5134 100644 --- a/oauth/.env.production +++ b/oauth/.env.production @@ -16,4 +16,4 @@ VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元 # Production settings - Disable development features VITE_ENABLE_TEST_UI=false -VITE_ENABLE_DEBUG=false \ No newline at end of file +VITE_ENABLE_DEBUG=true \ No newline at end of file diff --git a/oauth/src/components/RecordTabs.jsx b/oauth/src/components/RecordTabs.jsx index dd9e89e..ba68be9 100644 --- a/oauth/src/components/RecordTabs.jsx +++ b/oauth/src/components/RecordTabs.jsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useState, useEffect } from 'react' import RecordList from './RecordList.jsx' import ChatRecordList from './ChatRecordList.jsx' import ProfileRecordList from './ProfileRecordList.jsx' @@ -8,34 +8,59 @@ import { logger } from '../utils/logger.js' export default function RecordTabs({ langRecords, commentRecords, userComments, chatRecords, chatHasMore, onLoadMoreChat, userChatRecords, userChatLoading, baseRecords, apiConfig, pageContext, user = null, agent = null, onRecordDeleted = null }) { const [activeTab, setActiveTab] = useState('profiles') + // Monitor activeTab changes + useEffect(() => { + logger.log('RecordTabs: activeTab changed to', activeTab) + }, [activeTab]) + logger.log('RecordTabs: activeTab is', activeTab) + logger.log('RecordTabs: commentRecords prop:', commentRecords?.length || 0, commentRecords) // Filter records based on page context const filterRecords = (records, isProfile = false) => { // Ensure records is an array const recordsArray = Array.isArray(records) ? records : [] + logger.log('filterRecords called with:', { + recordsLength: recordsArray.length, + isProfile, + isTopPage: pageContext.isTopPage, + pageRkey: pageContext.rkey, + records: recordsArray + }) + if (pageContext.isTopPage) { // Top page: show latest 3 records - return recordsArray.slice(0, 3) + const result = recordsArray.slice(0, 3) + logger.log('filterRecords: Top page result:', result.length, result) + return result } else { // Individual page: show records matching the URL - return recordsArray.filter(record => { + const filtered = recordsArray.filter(record => { // Profile records should always be shown if (isProfile || record.value?.type === 'profile') { + logger.log('filterRecords: Profile record included:', record.value?.type) return true } const recordUrl = record.value?.post?.url - if (!recordUrl) return false + if (!recordUrl) { + logger.log('filterRecords: No recordUrl found for record:', record.value?.type) + return false + } try { const recordRkey = new URL(recordUrl).pathname.split('/').pop()?.replace(/\.html$/, '') - return recordRkey === pageContext.rkey + const matches = recordRkey === pageContext.rkey + logger.log('filterRecords: URL matching:', { recordRkey, pageRkey: pageContext.rkey, matches }) + return matches } catch { + logger.log('filterRecords: URL parsing failed for:', recordUrl) return false } }) + logger.log('filterRecords: Individual page result:', filtered.length, filtered) + return filtered } } @@ -44,7 +69,7 @@ export default function RecordTabs({ langRecords, commentRecords, userComments, // Ensure chatPairs is an array const chatArray = Array.isArray(chatPairs) ? chatPairs : [] - console.log('filterChatRecords called:', { + logger.log('filterChatRecords called:', { isTopPage: pageContext.isTopPage, rkey: pageContext.rkey, chatPairsLength: chatArray.length, @@ -55,14 +80,14 @@ export default function RecordTabs({ langRecords, commentRecords, userComments, if (pageContext.isTopPage) { // Top page: show latest 3 pairs const result = chatArray.slice(0, 3) - console.log('Top page: returning', result.length, 'pairs') + logger.log('Top page: returning', result.length, 'pairs') return result } else { // Individual page: show pairs matching the URL (compare path only, ignore domain) const filtered = chatArray.filter(chatPair => { const recordUrl = chatPair.question?.value?.post?.url if (!recordUrl) { - console.log('No recordUrl for chatPair:', chatPair) + logger.log('No recordUrl for chatPair:', chatPair) return false } @@ -71,31 +96,46 @@ export default function RecordTabs({ langRecords, commentRecords, userComments, const recordPath = new URL(recordUrl).pathname const recordRkey = recordPath.split('/').pop()?.replace(/\.html$/, '') - console.log('Comparing:', { recordRkey, pageRkey: pageContext.rkey, recordUrl }) + logger.log('Comparing:', { recordRkey, pageRkey: pageContext.rkey, recordUrl }) // Compare with current page rkey const matches = recordRkey === pageContext.rkey if (matches) { - console.log('Found matching chat pair!') + logger.log('Found matching chat pair!') } return matches } catch (error) { - console.log('Error processing recordUrl:', recordUrl, error) + logger.log('Error processing recordUrl:', recordUrl, error) return false } }) - console.log('Individual page: returning', filtered.length, 'filtered pairs') + logger.log('Individual page: returning', filtered.length, 'filtered pairs') return filtered } } const filteredLangRecords = filterRecords(Array.isArray(langRecords) ? langRecords : []) - const filteredCommentRecords = filterRecords(Array.isArray(commentRecords) ? commentRecords : []) - const filteredUserComments = filterRecords(Array.isArray(userComments) ? userComments : []) + + logger.log('RecordTabs: About to filter commentRecords:', commentRecords?.length || 0, commentRecords) + // User requested to display all comments without filtering + const filteredCommentRecords = Array.isArray(commentRecords) ? commentRecords : [] + logger.log('RecordTabs: After filtering commentRecords:', filteredCommentRecords.length, filteredCommentRecords) + + // User requested to display all comments without filtering + const filteredUserComments = Array.isArray(userComments) ? userComments : [] const filteredChatRecords = filterChatRecords(Array.isArray(chatRecords) ? chatRecords : []) const filteredBaseRecords = filterRecords(Array.isArray(baseRecords) ? baseRecords : []) + logger.log('RecordTabs: filtered results:') + logger.log(' - filteredCommentRecords:', filteredCommentRecords.length, filteredCommentRecords) + logger.log(' - filteredLangRecords:', filteredLangRecords.length) + logger.log(' - filteredUserComments:', filteredUserComments.length) + logger.log(' - pageContext:', pageContext) + logger.log('RecordTabs: TAB RENDER VALUES:') + logger.log(' - filteredCommentRecords.length for tab:', filteredCommentRecords.length) + logger.log(' - commentRecords input:', commentRecords?.length || 0) + // Filter profile records from baseRecords const profileRecords = (Array.isArray(baseRecords) ? baseRecords : []).filter(record => record.value?.type === 'profile') const sortedProfileRecords = profileRecords.sort((a, b) => { @@ -125,9 +165,15 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,