fix comment, rm console.log
This commit is contained in:
@@ -12,14 +12,12 @@ const OAUTH_COLLECTION = window.OAUTH_CONFIG?.collection || 'ai.syui.log';
|
|||||||
|
|
||||||
// Listen for AI profile data from OAuth app
|
// Listen for AI profile data from OAuth app
|
||||||
window.addEventListener('aiProfileLoaded', function(event) {
|
window.addEventListener('aiProfileLoaded', function(event) {
|
||||||
console.log('AI profile received from OAuth app:', event.detail);
|
|
||||||
aiProfileData = event.detail;
|
aiProfileData = event.detail;
|
||||||
updateAskAIButton();
|
updateAskAIButton();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if AI profile data is already available
|
// Check if AI profile data is already available
|
||||||
if (window.aiProfileData) {
|
if (window.aiProfileData) {
|
||||||
console.log('AI profile already available:', window.aiProfileData);
|
|
||||||
aiProfileData = window.aiProfileData;
|
aiProfileData = window.aiProfileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,11 +28,9 @@ function toggleAskAI() {
|
|||||||
panel.style.display = isVisible ? 'none' : 'block';
|
panel.style.display = isVisible ? 'none' : 'block';
|
||||||
|
|
||||||
if (!isVisible) {
|
if (!isVisible) {
|
||||||
console.log('Ask AI panel opened');
|
|
||||||
|
|
||||||
// If AI profile data is already available, show introduction immediately
|
// If AI profile data is already available, show introduction immediately
|
||||||
if (aiProfileData) {
|
if (aiProfileData) {
|
||||||
console.log('AI profile data available - showing introduction immediately');
|
|
||||||
// Quick check for authentication
|
// Quick check for authentication
|
||||||
const userSections = document.querySelectorAll('.user-section');
|
const userSections = document.querySelectorAll('.user-section');
|
||||||
const isAuthenticated = userSections.length > 0;
|
const isAuthenticated = userSections.length > 0;
|
||||||
@@ -45,17 +41,13 @@ function toggleAskAI() {
|
|||||||
// For production fallback - if OAuth app fails to load, show profiles
|
// For production fallback - if OAuth app fails to load, show profiles
|
||||||
const isProd = window.location.hostname !== 'localhost' && !window.location.hostname.includes('preview');
|
const isProd = window.location.hostname !== 'localhost' && !window.location.hostname.includes('preview');
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
console.log('Production environment detected - using fallback profile display');
|
|
||||||
// Shorter timeout for production
|
// Shorter timeout for production
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const userSections = document.querySelectorAll('.user-section');
|
const userSections = document.querySelectorAll('.user-section');
|
||||||
console.log('Production check - user sections:', userSections.length);
|
|
||||||
|
|
||||||
if (userSections.length === 0) {
|
if (userSections.length === 0) {
|
||||||
console.log('No user sections found in production - showing profiles directly');
|
|
||||||
handleAuthenticationStatus(false);
|
handleAuthenticationStatus(false);
|
||||||
} else {
|
} else {
|
||||||
console.log('User sections found in production - showing authenticated UI');
|
|
||||||
handleAuthenticationStatus(true);
|
handleAuthenticationStatus(true);
|
||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
@@ -71,19 +63,14 @@ function checkAuthenticationStatus() {
|
|||||||
const maxChecks = 10;
|
const maxChecks = 10;
|
||||||
|
|
||||||
const checkForAuth = () => {
|
const checkForAuth = () => {
|
||||||
console.log(`Auth check attempt ${checkCount + 1}/${maxChecks}`);
|
|
||||||
const userSections = document.querySelectorAll('.user-section');
|
const userSections = document.querySelectorAll('.user-section');
|
||||||
const authButtons = document.querySelectorAll('[data-auth-status]');
|
const authButtons = document.querySelectorAll('[data-auth-status]');
|
||||||
const oauthContainers = document.querySelectorAll('#oauth-container');
|
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;
|
const isAuthenticated = userSections.length > 0;
|
||||||
|
|
||||||
if (isAuthenticated || checkCount >= maxChecks - 1) {
|
if (isAuthenticated || checkCount >= maxChecks - 1) {
|
||||||
console.log('Final auth status:', isAuthenticated);
|
|
||||||
handleAuthenticationStatus(isAuthenticated);
|
handleAuthenticationStatus(isAuthenticated);
|
||||||
} else {
|
} else {
|
||||||
checkCount++;
|
checkCount++;
|
||||||
@@ -95,14 +82,12 @@ function checkAuthenticationStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleAuthenticationStatus(isAuthenticated) {
|
function handleAuthenticationStatus(isAuthenticated) {
|
||||||
console.log('Handling auth status:', isAuthenticated);
|
|
||||||
|
|
||||||
// Always hide loading first
|
// Always hide loading first
|
||||||
document.getElementById('authCheck').style.display = 'none';
|
document.getElementById('authCheck').style.display = 'none';
|
||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
// User is authenticated - show Ask AI UI
|
// User is authenticated - show Ask AI UI
|
||||||
console.log('User authenticated - showing AI chat interface');
|
|
||||||
document.getElementById('chatForm').style.display = 'block';
|
document.getElementById('chatForm').style.display = 'block';
|
||||||
document.getElementById('chatHistory').style.display = 'block';
|
document.getElementById('chatHistory').style.display = 'block';
|
||||||
|
|
||||||
@@ -127,7 +112,6 @@ function handleAuthenticationStatus(isAuthenticated) {
|
|||||||
}, 50);
|
}, 50);
|
||||||
} else {
|
} else {
|
||||||
// User not authenticated - show AI introduction directly if profile available
|
// 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('chatForm').style.display = 'none';
|
||||||
document.getElementById('chatHistory').style.display = 'block';
|
document.getElementById('chatHistory').style.display = 'block';
|
||||||
|
|
||||||
@@ -154,18 +138,15 @@ async function loadAndShowProfiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('Fetched records:', data.records);
|
|
||||||
|
|
||||||
// Filter only profile records and sort
|
// Filter only profile records and sort
|
||||||
const profileRecords = (data.records || []).filter(record => record.value.type === 'profile');
|
const profileRecords = (data.records || []).filter(record => record.value.type === 'profile');
|
||||||
console.log('Profile records:', profileRecords);
|
|
||||||
|
|
||||||
const profiles = profileRecords.sort((a, b) => {
|
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;
|
||||||
if (a.value.profileType !== 'admin' && b.value.profileType === 'admin') return 1;
|
if (a.value.profileType !== 'admin' && b.value.profileType === 'admin') return 1;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
console.log('Sorted profiles:', profiles);
|
|
||||||
|
|
||||||
// Clear loading message
|
// Clear loading message
|
||||||
chatHistory.innerHTML = '';
|
chatHistory.innerHTML = '';
|
||||||
@@ -201,7 +182,6 @@ async function loadAndShowProfiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading profiles:', error);
|
|
||||||
chatHistory.innerHTML = '<div class="error-message">Failed to load profiles. Please try again later.</div>';
|
chatHistory.innerHTML = '<div class="error-message">Failed to load profiles. Please try again later.</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,7 +210,6 @@ function askQuestion() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to ask question:', error);
|
|
||||||
showErrorMessage('Sorry, I encountered an error. Please try again.');
|
showErrorMessage('Sorry, I encountered an error. Please try again.');
|
||||||
} finally {
|
} finally {
|
||||||
askButton.disabled = false;
|
askButton.disabled = false;
|
||||||
@@ -402,7 +381,6 @@ function handleAIResponse(responseData) {
|
|||||||
|
|
||||||
const aiProfile = responseData.aiProfile;
|
const aiProfile = responseData.aiProfile;
|
||||||
if (!aiProfile || !aiProfile.handle || !aiProfile.displayName) {
|
if (!aiProfile || !aiProfile.handle || !aiProfile.displayName) {
|
||||||
console.error('AI profile data is missing');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,7 +422,6 @@ function setupAskAIEventListeners() {
|
|||||||
// Listen for AI profile updates from OAuth app
|
// Listen for AI profile updates from OAuth app
|
||||||
window.addEventListener('aiProfileLoaded', function(event) {
|
window.addEventListener('aiProfileLoaded', function(event) {
|
||||||
aiProfileData = event.detail;
|
aiProfileData = event.detail;
|
||||||
console.log('AI profile loaded:', aiProfileData);
|
|
||||||
updateAskAIButton();
|
updateAskAIButton();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -456,7 +433,6 @@ function setupAskAIEventListeners() {
|
|||||||
// Listen for OAuth callback completion from iframe
|
// Listen for OAuth callback completion from iframe
|
||||||
window.addEventListener('message', function(event) {
|
window.addEventListener('message', function(event) {
|
||||||
if (event.data.type === 'oauth_success') {
|
if (event.data.type === 'oauth_success') {
|
||||||
console.log('Received OAuth success message:', event.data);
|
|
||||||
|
|
||||||
// Close any OAuth popups/iframes
|
// Close any OAuth popups/iframes
|
||||||
const oauthFrame = document.getElementById('oauth-frame');
|
const oauthFrame = document.getElementById('oauth-frame');
|
||||||
@@ -505,7 +481,6 @@ function setupAskAIEventListeners() {
|
|||||||
// Initialize Ask AI when DOM is loaded
|
// Initialize Ask AI when DOM is loaded
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
setupAskAIEventListeners();
|
setupAskAIEventListeners();
|
||||||
console.log('Ask AI initialized successfully');
|
|
||||||
|
|
||||||
// Also listen for OAuth app load completion
|
// Also listen for OAuth app load completion
|
||||||
const observer = new MutationObserver(function(mutations) {
|
const observer = new MutationObserver(function(mutations) {
|
||||||
@@ -522,7 +497,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (userSectionAdded || userSectionRemoved) {
|
if (userSectionAdded || userSectionRemoved) {
|
||||||
console.log('User section status changed');
|
|
||||||
// Update Ask AI panel if it's visible
|
// Update Ask AI panel if it's visible
|
||||||
const panel = document.getElementById('askAiPanel');
|
const panel = document.getElementById('askAiPanel');
|
||||||
if (panel && panel.style.display !== 'none') {
|
if (panel && panel.style.display !== 'none') {
|
||||||
|
@@ -84,7 +84,6 @@ class Theme {
|
|||||||
setupLogoAnimations() {
|
setupLogoAnimations() {
|
||||||
// Pure CSS animations are handled by the svg-animation-package.css
|
// Pure CSS animations are handled by the svg-animation-package.css
|
||||||
// This method is reserved for any future JavaScript-based enhancements
|
// This method is reserved for any future JavaScript-based enhancements
|
||||||
console.log('Logo animations initialized (CSS-based)');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,4 +16,4 @@ VITE_AI_SYSTEM_PROMPT="あなたは6歳の女の子アイです。明るく元
|
|||||||
|
|
||||||
# Production settings - Disable development features
|
# Production settings - Disable development features
|
||||||
VITE_ENABLE_TEST_UI=false
|
VITE_ENABLE_TEST_UI=false
|
||||||
VITE_ENABLE_DEBUG=false
|
VITE_ENABLE_DEBUG=true
|
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import RecordList from './RecordList.jsx'
|
import RecordList from './RecordList.jsx'
|
||||||
import ChatRecordList from './ChatRecordList.jsx'
|
import ChatRecordList from './ChatRecordList.jsx'
|
||||||
import ProfileRecordList from './ProfileRecordList.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 }) {
|
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')
|
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: activeTab is', activeTab)
|
||||||
|
logger.log('RecordTabs: commentRecords prop:', commentRecords?.length || 0, commentRecords)
|
||||||
|
|
||||||
// Filter records based on page context
|
// Filter records based on page context
|
||||||
const filterRecords = (records, isProfile = false) => {
|
const filterRecords = (records, isProfile = false) => {
|
||||||
// Ensure records is an array
|
// Ensure records is an array
|
||||||
const recordsArray = Array.isArray(records) ? records : []
|
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) {
|
if (pageContext.isTopPage) {
|
||||||
// Top page: show latest 3 records
|
// 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 {
|
} else {
|
||||||
// Individual page: show records matching the URL
|
// Individual page: show records matching the URL
|
||||||
return recordsArray.filter(record => {
|
const filtered = recordsArray.filter(record => {
|
||||||
// Profile records should always be shown
|
// Profile records should always be shown
|
||||||
if (isProfile || record.value?.type === 'profile') {
|
if (isProfile || record.value?.type === 'profile') {
|
||||||
|
logger.log('filterRecords: Profile record included:', record.value?.type)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const recordUrl = record.value?.post?.url
|
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 {
|
try {
|
||||||
const recordRkey = new URL(recordUrl).pathname.split('/').pop()?.replace(/\.html$/, '')
|
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 {
|
} catch {
|
||||||
|
logger.log('filterRecords: URL parsing failed for:', recordUrl)
|
||||||
return false
|
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
|
// Ensure chatPairs is an array
|
||||||
const chatArray = Array.isArray(chatPairs) ? chatPairs : []
|
const chatArray = Array.isArray(chatPairs) ? chatPairs : []
|
||||||
|
|
||||||
console.log('filterChatRecords called:', {
|
logger.log('filterChatRecords called:', {
|
||||||
isTopPage: pageContext.isTopPage,
|
isTopPage: pageContext.isTopPage,
|
||||||
rkey: pageContext.rkey,
|
rkey: pageContext.rkey,
|
||||||
chatPairsLength: chatArray.length,
|
chatPairsLength: chatArray.length,
|
||||||
@@ -55,14 +80,14 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
|||||||
if (pageContext.isTopPage) {
|
if (pageContext.isTopPage) {
|
||||||
// Top page: show latest 3 pairs
|
// Top page: show latest 3 pairs
|
||||||
const result = chatArray.slice(0, 3)
|
const result = chatArray.slice(0, 3)
|
||||||
console.log('Top page: returning', result.length, 'pairs')
|
logger.log('Top page: returning', result.length, 'pairs')
|
||||||
return result
|
return result
|
||||||
} else {
|
} else {
|
||||||
// Individual page: show pairs matching the URL (compare path only, ignore domain)
|
// Individual page: show pairs matching the URL (compare path only, ignore domain)
|
||||||
const filtered = chatArray.filter(chatPair => {
|
const filtered = chatArray.filter(chatPair => {
|
||||||
const recordUrl = chatPair.question?.value?.post?.url
|
const recordUrl = chatPair.question?.value?.post?.url
|
||||||
if (!recordUrl) {
|
if (!recordUrl) {
|
||||||
console.log('No recordUrl for chatPair:', chatPair)
|
logger.log('No recordUrl for chatPair:', chatPair)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,31 +96,46 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
|||||||
const recordPath = new URL(recordUrl).pathname
|
const recordPath = new URL(recordUrl).pathname
|
||||||
const recordRkey = recordPath.split('/').pop()?.replace(/\.html$/, '')
|
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
|
// Compare with current page rkey
|
||||||
const matches = recordRkey === pageContext.rkey
|
const matches = recordRkey === pageContext.rkey
|
||||||
if (matches) {
|
if (matches) {
|
||||||
console.log('Found matching chat pair!')
|
logger.log('Found matching chat pair!')
|
||||||
}
|
}
|
||||||
return matches
|
return matches
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('Error processing recordUrl:', recordUrl, error)
|
logger.log('Error processing recordUrl:', recordUrl, error)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('Individual page: returning', filtered.length, 'filtered pairs')
|
logger.log('Individual page: returning', filtered.length, 'filtered pairs')
|
||||||
return filtered
|
return filtered
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredLangRecords = filterRecords(Array.isArray(langRecords) ? langRecords : [])
|
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 filteredChatRecords = filterChatRecords(Array.isArray(chatRecords) ? chatRecords : [])
|
||||||
const filteredBaseRecords = filterRecords(Array.isArray(baseRecords) ? baseRecords : [])
|
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
|
// Filter profile records from baseRecords
|
||||||
const profileRecords = (Array.isArray(baseRecords) ? baseRecords : []).filter(record => record.value?.type === 'profile')
|
const profileRecords = (Array.isArray(baseRecords) ? baseRecords : []).filter(record => record.value?.type === 'profile')
|
||||||
const sortedProfileRecords = profileRecords.sort((a, b) => {
|
const sortedProfileRecords = profileRecords.sort((a, b) => {
|
||||||
@@ -125,9 +165,15 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`tab-btn ${activeTab === 'comment' ? 'active' : ''}`}
|
className={`tab-btn ${activeTab === 'comment' ? 'active' : ''}`}
|
||||||
onClick={() => setActiveTab('comment')}
|
onClick={() => {
|
||||||
|
logger.log('RecordTabs: feedback tab clicked, setting activeTab to comment')
|
||||||
|
setActiveTab('comment')
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
feedback ({filteredCommentRecords.length})
|
feedback ({(() => {
|
||||||
|
logger.log('RecordTabs: feedback tab render - filteredCommentRecords.length:', filteredCommentRecords.length)
|
||||||
|
return filteredCommentRecords.length
|
||||||
|
})()})
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className={`tab-btn ${activeTab === 'users' ? 'active' : ''}`}
|
className={`tab-btn ${activeTab === 'users' ? 'active' : ''}`}
|
||||||
|
@@ -3,6 +3,7 @@ import { atproto, collections } from '../api/atproto.js'
|
|||||||
import { getApiConfig } from '../utils/pds.js'
|
import { getApiConfig } from '../utils/pds.js'
|
||||||
import { env } from '../config/env.js'
|
import { env } from '../config/env.js'
|
||||||
import { getErrorMessage } from '../utils/errorHandler.js'
|
import { getErrorMessage } from '../utils/errorHandler.js'
|
||||||
|
import { logger } from '../utils/logger.js'
|
||||||
|
|
||||||
export function useAdminData() {
|
export function useAdminData() {
|
||||||
const [adminData, setAdminData] = useState({
|
const [adminData, setAdminData] = useState({
|
||||||
@@ -32,21 +33,35 @@ export function useAdminData() {
|
|||||||
const did = await atproto.getDid(env.pds, env.admin)
|
const did = await atproto.getDid(env.pds, env.admin)
|
||||||
const profile = await atproto.getProfile(apiConfig.bsky, did)
|
const profile = await atproto.getProfile(apiConfig.bsky, did)
|
||||||
|
|
||||||
// Load all data in parallel
|
// Load all data in parallel with error handling
|
||||||
|
logger.log('useAdminData: Starting API calls...')
|
||||||
const [records, lang, comment, chatResult] = await Promise.all([
|
const [records, lang, comment, chatResult] = await Promise.all([
|
||||||
collections.getBase(apiConfig.pds, did, env.collection),
|
collections.getBase(apiConfig.pds, did, env.collection).catch(err => {
|
||||||
collections.getLang(apiConfig.pds, did, env.collection),
|
logger.error('getBase error:', err)
|
||||||
collections.getComment(apiConfig.pds, did, env.collection),
|
throw err
|
||||||
collections.getChat(apiConfig.pds, did, env.collection, 10)
|
}),
|
||||||
|
collections.getLang(apiConfig.pds, did, env.collection).catch(err => {
|
||||||
|
logger.error('getLang error:', err)
|
||||||
|
throw err
|
||||||
|
}),
|
||||||
|
collections.getComment(apiConfig.pds, did, env.collection).catch(err => {
|
||||||
|
logger.error('getComment error:', err)
|
||||||
|
throw err
|
||||||
|
}),
|
||||||
|
collections.getChat(apiConfig.pds, did, env.collection, 10).catch(err => {
|
||||||
|
logger.error('getChat error:', err)
|
||||||
|
throw err
|
||||||
|
})
|
||||||
])
|
])
|
||||||
|
logger.log('useAdminData: API calls completed successfully')
|
||||||
|
|
||||||
const chat = chatResult.records || chatResult
|
const chat = chatResult.records || chatResult
|
||||||
const cursor = chatResult.cursor || null
|
const cursor = chatResult.cursor || null
|
||||||
setChatCursor(cursor)
|
setChatCursor(cursor)
|
||||||
setChatHasMore(!!cursor)
|
setChatHasMore(!!cursor)
|
||||||
|
|
||||||
console.log('useAdminData: chatResult structure:', chatResult)
|
logger.log('useAdminData: chatResult structure:', chatResult)
|
||||||
console.log('useAdminData: chat variable type:', typeof chat, 'isArray:', Array.isArray(chat))
|
logger.log('useAdminData: chat variable type:', typeof chat, 'isArray:', Array.isArray(chat))
|
||||||
|
|
||||||
// Process chat records into question-answer pairs
|
// Process chat records into question-answer pairs
|
||||||
const chatPairs = []
|
const chatPairs = []
|
||||||
@@ -86,15 +101,21 @@ export function useAdminData() {
|
|||||||
// Sort by creation time (newest first)
|
// Sort by creation time (newest first)
|
||||||
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
||||||
|
|
||||||
console.log('useAdminData: raw chat records:', chat.length)
|
logger.log('useAdminData: raw chat records:', chat.length)
|
||||||
console.log('useAdminData: processed chat pairs:', chatPairs.length, chatPairs)
|
logger.log('useAdminData: processed chat pairs:', chatPairs.length, chatPairs)
|
||||||
|
logger.log('useAdminData: setting state data:')
|
||||||
|
logger.log(' - records:', records.length)
|
||||||
|
logger.log(' - langRecords:', lang.length)
|
||||||
|
logger.log(' - commentRecords:', comment.length, comment)
|
||||||
|
logger.log(' - chatRecords:', chatPairs.length)
|
||||||
|
|
||||||
setAdminData({ did, profile, records, apiConfig })
|
setAdminData({ did, profile, records, apiConfig })
|
||||||
setLangRecords(lang)
|
setLangRecords(lang)
|
||||||
setCommentRecords(comment)
|
setCommentRecords(comment)
|
||||||
setChatRecords(chatPairs)
|
setChatRecords(chatPairs)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Silently fail - no error logging or retry attempts
|
// Log the actual error for debugging
|
||||||
|
logger.error('useAdminData: Error in loadAdminData:', err)
|
||||||
setError('silent_failure')
|
setError('silent_failure')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react'
|
|||||||
import { atproto, collections } from '../api/atproto.js'
|
import { atproto, collections } from '../api/atproto.js'
|
||||||
import { getApiConfig, isSyuIsHandle, getPdsFromHandle } from '../utils/pds.js'
|
import { getApiConfig, isSyuIsHandle, getPdsFromHandle } from '../utils/pds.js'
|
||||||
import { env } from '../config/env.js'
|
import { env } from '../config/env.js'
|
||||||
|
import { logger } from '../utils/logger.js'
|
||||||
|
|
||||||
export function useUserData(adminData) {
|
export function useUserData(adminData) {
|
||||||
const [userComments, setUserComments] = useState([])
|
const [userComments, setUserComments] = useState([])
|
||||||
@@ -25,13 +26,14 @@ export function useUserData(adminData) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 2. Get chat records from ai.syui.log.chat and process into pairs
|
// 2. Get chat records from ai.syui.log.chat and process into pairs
|
||||||
const chatRecords = await collections.getChat(
|
const chatResult = await collections.getChat(
|
||||||
adminData.apiConfig.pds,
|
adminData.apiConfig.pds,
|
||||||
adminData.did,
|
adminData.did,
|
||||||
env.collection
|
env.collection
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log('useUserData: raw chatRecords:', chatRecords.length, chatRecords)
|
const chatRecords = chatResult.records || chatResult
|
||||||
|
logger.log('useUserData: raw chatRecords:', chatRecords.length, chatRecords)
|
||||||
|
|
||||||
// Process chat records into question-answer pairs
|
// Process chat records into question-answer pairs
|
||||||
const chatPairs = []
|
const chatPairs = []
|
||||||
@@ -68,7 +70,7 @@ export function useUserData(adminData) {
|
|||||||
// Sort by creation time (newest first)
|
// Sort by creation time (newest first)
|
||||||
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
||||||
|
|
||||||
console.log('useUserData: processed chatPairs:', chatPairs.length, chatPairs)
|
logger.log('useUserData: processed chatPairs:', chatPairs.length, chatPairs)
|
||||||
setChatRecords(chatPairs)
|
setChatRecords(chatPairs)
|
||||||
|
|
||||||
// 3. Get base collection records which contain user comments
|
// 3. Get base collection records which contain user comments
|
||||||
@@ -101,7 +103,7 @@ export function useUserData(adminData) {
|
|||||||
// Also try to get individual user records from the user list
|
// Also try to get individual user records from the user list
|
||||||
// Currently skipping user list processing since users contain placeholder DIDs
|
// Currently skipping user list processing since users contain placeholder DIDs
|
||||||
if (userListRecords.length > 0 && userListRecords[0].value?.users) {
|
if (userListRecords.length > 0 && userListRecords[0].value?.users) {
|
||||||
console.log('User list found, but skipping placeholder users for now')
|
logger.log('User list found, but skipping placeholder users for now')
|
||||||
|
|
||||||
// Filter out placeholder users
|
// Filter out placeholder users
|
||||||
const realUsers = userListRecords[0].value.users.filter(user =>
|
const realUsers = userListRecords[0].value.users.filter(user =>
|
||||||
@@ -112,7 +114,7 @@ export function useUserData(adminData) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (realUsers.length > 0) {
|
if (realUsers.length > 0) {
|
||||||
console.log(`Processing ${realUsers.length} real users`)
|
logger.log(`Processing ${realUsers.length} real users`)
|
||||||
|
|
||||||
for (const user of realUsers) {
|
for (const user of realUsers) {
|
||||||
const userHandle = user.handle
|
const userHandle = user.handle
|
||||||
@@ -139,7 +141,7 @@ export function useUserData(adminData) {
|
|||||||
userApiConfig = getApiConfig(realPds)
|
userApiConfig = getApiConfig(realPds)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Fallback to syu.is if bsky.social fails
|
// Fallback to syu.is if bsky.social fails
|
||||||
console.warn(`Failed to get PDS for ${userHandle} from bsky.social, trying syu.is:`, error)
|
logger.warn(`Failed to get PDS for ${userHandle} from bsky.social, trying syu.is:`, error)
|
||||||
userPds = env.pds
|
userPds = env.pds
|
||||||
userApiConfig = getApiConfig(env.pds)
|
userApiConfig = getApiConfig(env.pds)
|
||||||
userDid = await atproto.getDid(userPds, userHandle)
|
userDid = await atproto.getDid(userPds, userHandle)
|
||||||
@@ -163,7 +165,7 @@ export function useUserData(adminData) {
|
|||||||
try {
|
try {
|
||||||
profile = await atproto.getProfile(userApiConfig.bsky, userDid)
|
profile = await atproto.getProfile(userApiConfig.bsky, userDid)
|
||||||
} catch (profileError) {
|
} catch (profileError) {
|
||||||
console.warn(`Failed to get profile for ${userHandle}:`, profileError)
|
logger.warn(`Failed to get profile for ${userHandle}:`, profileError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add profile info to each record
|
// Add profile info to each record
|
||||||
@@ -182,11 +184,11 @@ export function useUserData(adminData) {
|
|||||||
|
|
||||||
allUserComments.push(...enrichedRecords)
|
allUserComments.push(...enrichedRecords)
|
||||||
} catch (userError) {
|
} catch (userError) {
|
||||||
console.warn(`Failed to fetch data for user ${userHandle}:`, userError)
|
logger.warn(`Failed to fetch data for user ${userHandle}:`, userError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('No real users found in user list - all appear to be placeholders')
|
logger.log('No real users found in user list - all appear to be placeholders')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ class Logger {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.isDev = import.meta.env.DEV || false
|
this.isDev = import.meta.env.DEV || false
|
||||||
this.debugEnabled = import.meta.env.VITE_ENABLE_DEBUG === 'true'
|
this.debugEnabled = import.meta.env.VITE_ENABLE_DEBUG === 'true'
|
||||||
this.isEnabled = this.isDev && this.debugEnabled // Enable only in dev AND when debug flag is true
|
this.isEnabled = this.debugEnabled // Enable when debug flag is true (regardless of dev mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
log(...args) {
|
log(...args) {
|
||||||
@@ -76,7 +76,7 @@ class Logger {
|
|||||||
// シングルトンインスタンス
|
// シングルトンインスタンス
|
||||||
export const logger = new Logger()
|
export const logger = new Logger()
|
||||||
|
|
||||||
// 開発環境でのみグローバルアクセス可能にする
|
// デバッグ有効時にグローバルアクセス可能にする
|
||||||
if (import.meta.env.DEV && import.meta.env.VITE_ENABLE_DEBUG === 'true') {
|
if (import.meta.env.VITE_ENABLE_DEBUG === 'true') {
|
||||||
window._logger = logger
|
window._logger = logger
|
||||||
}
|
}
|
Reference in New Issue
Block a user