Browse Source

fixed subtopics

imwald
Silberengel 5 months ago
parent
commit
f47fd87674
  1. 14
      src/pages/primary/DiscussionsPage/CreateThreadDialog.tsx
  2. 52
      src/pages/primary/DiscussionsPage/index.tsx

14
src/pages/primary/DiscussionsPage/CreateThreadDialog.tsx

@ -222,14 +222,18 @@ export default function CreateThreadDialog({
// Build tags array // Build tags array
const tags = [ const tags = [
['title', title.trim()], ['title', title.trim()],
['t', normalizeTopic(selectedTopic)],
['-'] // Required tag for relay privacy ['-'] // Required tag for relay privacy
] ]
// Add hashtags as t-tags (deduplicate with selectedTopic) // Only add topic tag if it's a specific topic (not 'all' or 'general')
const uniqueHashtags = hashtags.filter( if (selectedTopic !== 'all' && selectedTopic !== 'general') {
hashtag => hashtag !== normalizeTopic(selectedTopic) tags.push(['t', normalizeTopic(selectedTopic)])
) }
// Add hashtags as t-tags (deduplicate with selectedTopic if it's not 'all' or 'general')
const uniqueHashtags = (selectedTopic !== 'all' && selectedTopic !== 'general')
? hashtags.filter(hashtag => hashtag !== normalizeTopic(selectedTopic))
: hashtags
for (const hashtag of uniqueHashtags) { for (const hashtag of uniqueHashtags) {
tags.push(['t', hashtag]) tags.push(['t', hashtag])
} }

52
src/pages/primary/DiscussionsPage/index.tsx

@ -31,6 +31,11 @@ function normalizeSubtopic(tag: string): string {
return normalized return normalized
} }
// Don't normalize compound hashtags (with hyphens or underscores)
if (normalized.includes('-') || normalized.includes('_')) {
return normalized
}
// Handle common suffixes to find root forms // Handle common suffixes to find root forms
// Remove trailing 's' for plurals (but not if word ends in 'ss') // Remove trailing 's' for plurals (but not if word ends in 'ss')
@ -168,18 +173,7 @@ function analyzeDynamicTopicsAndSubtopics(eventMap: Map<string, EventMapEntry>):
return { dynamicTopics, dynamicSubtopics } return { dynamicTopics, dynamicSubtopics }
} }
// Function to get dynamic subtopics from event topics // Removed getSubtopicsFromTopics - now using only dynamicSubtopics that meet npub thresholds
function getSubtopicsFromTopics(topics: string[], limit: number = 3): string[] {
// Get the main topic IDs from DISCUSSION_TOPICS
const mainTopicIds = DISCUSSION_TOPICS.map(topic => topic.id)
// Filter out main topic IDs and get unique subtopics
const subtopics = topics.filter(topic => !mainTopicIds.includes(topic))
const uniqueSubtopics = [...new Set(subtopics)]
// Return the most common subtopics, limited by the limit
return uniqueSubtopics.slice(0, limit)
}
// Simple event map type // Simple event map type
type EventMapEntry = { type EventMapEntry = {
@ -533,25 +527,25 @@ const DiscussionsPage = forwardRef((_, ref) => {
// Update available subtopics when topic analysis or selected topic changes // Update available subtopics when topic analysis or selected topic changes
useEffect(() => { useEffect(() => {
if (selectedTopic && selectedTopic !== 'all') { if (selectedTopic && selectedTopic !== 'all') {
// Get all topics from events in this topic // Only show dynamic subtopics that meet the 3-npub threshold
// Don't use getSubtopicsFromTopics as it doesn't respect npub thresholds
const relevantDynamicSubtopics = dynamicSubtopics.filter(subtopic => {
// Check if this subtopic appears in events for this topic
const topicEvents = Array.from(eventMap.values()).filter(entry => entry.categorizedTopic === selectedTopic) const topicEvents = Array.from(eventMap.values()).filter(entry => entry.categorizedTopic === selectedTopic)
const allTopics = topicEvents.flatMap(entry => entry.allTopics) const appearsInTopic = topicEvents.some(entry => entry.allTopics.includes(subtopic))
const subtopics = getSubtopicsFromTopics(allTopics, 10) // Increased limit to show more subtopics return appearsInTopic
})
// Add relevant dynamic subtopics for this topic
const relevantDynamicSubtopics = dynamicSubtopics.filter(subtopic =>
allTopics.includes(subtopic)
)
// Combine and deduplicate
const combinedSubtopics = [...new Set([...subtopics, ...relevantDynamicSubtopics])]
// Special case: Always include 'readings' as a subtopic for 'literature' // Special case: Always include 'readings' as a subtopic for 'literature' if it appears
if (selectedTopic === 'literature' && !combinedSubtopics.includes('readings')) { if (selectedTopic === 'literature') {
combinedSubtopics.unshift('readings') const topicEvents = Array.from(eventMap.values()).filter(entry => entry.categorizedTopic === selectedTopic)
const hasReadings = topicEvents.some(entry => entry.allTopics.includes('readings'))
if (hasReadings && !relevantDynamicSubtopics.includes('readings')) {
relevantDynamicSubtopics.unshift('readings')
}
} }
setAvailableSubtopics(combinedSubtopics) setAvailableSubtopics(relevantDynamicSubtopics)
} else if (selectedTopic === 'general') { } else if (selectedTopic === 'general') {
// For General topic, show dynamic subtopics that don't belong to other topics // For General topic, show dynamic subtopics that don't belong to other topics
const generalSubtopics = dynamicSubtopics.filter(subtopic => { const generalSubtopics = dynamicSubtopics.filter(subtopic => {
@ -908,7 +902,7 @@ const DiscussionsPage = forwardRef((_, ref) => {
const entry = eventMap.get(event.id) const entry = eventMap.get(event.id)
const threadSubtopics = entry?.categorizedTopic === 'literature' const threadSubtopics = entry?.categorizedTopic === 'literature'
? ['readings'] ? ['readings']
: getSubtopicsFromTopics(entry?.allTopics || [], 3) : entry?.allTopics || []
return ( return (
<ThreadCard <ThreadCard
@ -932,7 +926,7 @@ const DiscussionsPage = forwardRef((_, ref) => {
const entry = eventMap.get(event.id) const entry = eventMap.get(event.id)
const threadSubtopics = entry?.categorizedTopic === 'literature' const threadSubtopics = entry?.categorizedTopic === 'literature'
? ['readings'] ? ['readings']
: getSubtopicsFromTopics(entry?.allTopics || [], 3) : entry?.allTopics || []
return ( return (
<ThreadCard <ThreadCard

Loading…
Cancel
Save