From 5963c6b11e8e6b9760133a760b35ddad3dfc5f50 Mon Sep 17 00:00:00 2001 From: syui Date: Wed, 25 Jun 2025 21:35:03 +0900 Subject: [PATCH] fix test ask-AI oauth profile --- my-blog/static/js/ask-ai.js | 44 +++++++++++++++++++++++++++-- oauth/src/components/RecordTabs.jsx | 14 ++++----- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/my-blog/static/js/ask-ai.js b/my-blog/static/js/ask-ai.js index 22ecefa..f694b51 100644 --- a/my-blog/static/js/ask-ai.js +++ b/my-blog/static/js/ask-ai.js @@ -17,9 +17,16 @@ function toggleAskAI() { } function checkAuthenticationStatus() { - const userSections = document.querySelectorAll('.user-section'); - const isAuthenticated = userSections.length > 0; - + // Wait a bit for OAuth app to load if needed + setTimeout(() => { + const userSections = document.querySelectorAll('.user-section'); + const isAuthenticated = userSections.length > 0; + + handleAuthenticationStatus(isAuthenticated); + }, 100); +} + +function handleAuthenticationStatus(isAuthenticated) { if (isAuthenticated) { // User is authenticated - show Ask AI UI document.getElementById('authCheck').style.display = 'none'; @@ -377,6 +384,37 @@ function setupAskAIEventListeners() { document.addEventListener('DOMContentLoaded', function() { setupAskAIEventListeners(); console.log('Ask AI initialized successfully'); + + // Also listen for OAuth app load completion + const observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + if (mutation.type === 'childList') { + // Check if user-section was added/removed + const userSectionAdded = Array.from(mutation.addedNodes).some(node => + node.nodeType === Node.ELEMENT_NODE && + (node.classList?.contains('user-section') || node.querySelector?.('.user-section')) + ); + const userSectionRemoved = Array.from(mutation.removedNodes).some(node => + node.nodeType === Node.ELEMENT_NODE && + (node.classList?.contains('user-section') || node.querySelector?.('.user-section')) + ); + + 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') { + checkAuthenticationStatus(); + } + } + } + }); + }); + + observer.observe(document.body, { + childList: true, + subtree: true + }); }); // Global functions for onclick handlers diff --git a/oauth/src/components/RecordTabs.jsx b/oauth/src/components/RecordTabs.jsx index 9bf8d4a..9d51cc3 100644 --- a/oauth/src/components/RecordTabs.jsx +++ b/oauth/src/components/RecordTabs.jsx @@ -64,17 +64,17 @@ export default function RecordTabs({ langRecords, commentRecords, userComments, > chat ({userChatRecords?.length || 0}) - +