cleanup
This commit is contained in:
@@ -13,8 +13,6 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
||||
const [pageSpecificChatRecords, setPageSpecificChatRecords] = useState([])
|
||||
const [pageSpecificLoading, setPageSpecificLoading] = useState(false)
|
||||
|
||||
|
||||
|
||||
// Check if current page has matching chat records (AI posts always have chat records)
|
||||
const isAiPost = !pageContext.isTopPage && Array.isArray(chatRecords) && chatRecords.some(chatPair => {
|
||||
const recordUrl = chatPair.question?.value?.post?.url
|
||||
@@ -30,10 +28,9 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
||||
|
||||
const [activeTab, setActiveTab] = useState(isAiPost ? 'collection' : 'profiles')
|
||||
|
||||
// Fixed useEffect with proper dependency array
|
||||
// Fetch page-specific chat records for individual article pages
|
||||
useEffect(() => {
|
||||
if (!pageContext.isTopPage && pageContext.rkey) {
|
||||
|
||||
const fetchPageSpecificChats = async () => {
|
||||
setPageSpecificLoading(true)
|
||||
try {
|
||||
@@ -59,15 +56,12 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
||||
} else {
|
||||
setPageSpecificChatRecords([])
|
||||
}
|
||||
}, [pageContext.isTopPage, pageContext.rkey]) // Add proper dependencies
|
||||
|
||||
}, [pageContext.isTopPage, pageContext.rkey])
|
||||
|
||||
// Filter records based on page context
|
||||
const filterRecords = (records, isProfile = false) => {
|
||||
// Ensure records is an array
|
||||
const recordsArray = Array.isArray(records) ? records : []
|
||||
|
||||
|
||||
if (pageContext.isTopPage) {
|
||||
// Top page: show latest 3 records
|
||||
return recordsArray.slice(0, 3)
|
||||
@@ -95,12 +89,10 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
||||
}
|
||||
}
|
||||
|
||||
// Special filter for chat records (which are already processed into pairs)
|
||||
// Filter chat records (which are already processed into pairs)
|
||||
const filterChatRecords = (chatPairs) => {
|
||||
// Ensure chatPairs is an array
|
||||
const chatArray = Array.isArray(chatPairs) ? chatPairs : []
|
||||
|
||||
|
||||
if (pageContext.isTopPage) {
|
||||
// Top page: show latest 3 pairs
|
||||
return chatArray.slice(0, 3)
|
||||
@@ -128,15 +120,13 @@ export default function RecordTabs({ langRecords, commentRecords, userComments,
|
||||
}
|
||||
}
|
||||
|
||||
// Apply filters to all record types
|
||||
const filteredLangRecords = filterRecords(Array.isArray(langRecords) ? langRecords : [])
|
||||
|
||||
const filteredCommentRecords = filterRecords(Array.isArray(commentRecords) ? commentRecords : [])
|
||||
|
||||
const filteredUserComments = filterRecords(Array.isArray(userComments) ? userComments : [])
|
||||
const filteredChatRecords = filterChatRecords(Array.isArray(chatRecords) ? chatRecords : [])
|
||||
const filteredBaseRecords = filterRecords(Array.isArray(baseRecords) ? baseRecords : [])
|
||||
|
||||
|
||||
// Filter profile records from baseRecords
|
||||
const profileRecords = (Array.isArray(baseRecords) ? baseRecords : []).filter(record => record.value?.type === 'profile')
|
||||
const sortedProfileRecords = profileRecords.sort((a, b) => {
|
||||
|
@@ -105,21 +105,12 @@ export function useAdminData() {
|
||||
return dateA - dateB
|
||||
})
|
||||
|
||||
logger.log('useAdminData: raw chat records:', chat.length)
|
||||
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 })
|
||||
setLangRecords(lang)
|
||||
setCommentRecords(comment)
|
||||
setChatRecords(chatPairs)
|
||||
} catch (err) {
|
||||
// Log the actual error for debugging
|
||||
logger.error('useAdminData: Error in loadAdminData:', err)
|
||||
setError('silent_failure')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
|
@@ -67,8 +67,8 @@ export function useUserData(adminData) {
|
||||
}
|
||||
})
|
||||
|
||||
// Sort by creation time (newest first)
|
||||
chatPairs.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
||||
// Sort by creation time (oldest first) - consistent with other components
|
||||
chatPairs.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt))
|
||||
|
||||
logger.log('useUserData: processed chatPairs:', chatPairs.length, chatPairs)
|
||||
setChatRecords(chatPairs)
|
||||
|
Reference in New Issue
Block a user