web-app/src/modules/nostr-feed/composables/useFeed.ts
padreug f05398fa9e Enhance FeedService filtering logic
- Added a watch function in useFeed to log updates to filtered posts,
aiding in debugging.
- Updated content filters to include text notes in announcements and
marketplace presets, ensuring broader content visibility.
- Enhanced FeedService to log detailed information during custom
filtering, improving traceability of filtering logic.
- Modified Home.vue to always use custom filters for better consistency
in feed display.

These changes improve the reactivity, flexibility, and clarity of the
feed system, enhancing the overall user experience.
2025-09-23 23:59:37 +02:00

93 lines
No EOL
2.5 KiB
TypeScript

import { computed, ref, onMounted, onUnmounted, watch } from 'vue'
import { injectService, SERVICE_TOKENS } from '@/core/di-container'
import type { FeedService, FeedConfig, ContentFilter } from '../services/FeedService'
export interface UseFeedConfig {
feedType: 'announcements' | 'general' | 'mentions' | 'events' | 'all' | 'custom'
maxPosts?: number
refreshInterval?: number
adminPubkeys?: string[]
contentFilters?: ContentFilter[]
}
export function useFeed(config: UseFeedConfig) {
const feedService = injectService<FeedService>(SERVICE_TOKENS.FEED_SERVICE)
console.log('useFeed: FeedService injected:', !!feedService)
if (!feedService) {
console.error('useFeed: FeedService not available from DI container')
}
let refreshTimer: number | null = null
// Convert to FeedService config
const feedConfig: FeedConfig = {
feedType: config.feedType,
maxPosts: config.maxPosts,
adminPubkeys: config.adminPubkeys,
contentFilters: config.contentFilters
}
const filteredPosts = computed(() => {
if (!feedService) return []
return feedService.getFilteredPosts(feedConfig)
})
const loadFeed = async () => {
console.log('useFeed: loadFeed called, feedService available:', !!feedService)
if (!feedService) {
console.error('FeedService not available')
return
}
console.log('useFeed: calling feedService.subscribeFeed with config:', feedConfig)
try {
await feedService.subscribeFeed(feedConfig)
console.log('useFeed: subscribeFeed completed')
} catch (err) {
console.error('Failed to load feed:', err)
}
}
const refreshFeed = async () => {
if (!feedService) return
await feedService.refreshFeed()
}
const startAutoRefresh = () => {
if (config.refreshInterval && config.refreshInterval > 0) {
refreshTimer = setInterval(refreshFeed, config.refreshInterval) as unknown as number
}
}
const stopAutoRefresh = () => {
if (refreshTimer) {
clearInterval(refreshTimer)
refreshTimer = null
}
}
// Lifecycle
onMounted(() => {
console.log('useFeed: onMounted called')
loadFeed()
startAutoRefresh()
})
onUnmounted(() => {
stopAutoRefresh()
})
// Debug posts reactivity
watch(filteredPosts, (newPosts) => {
console.log('useFeed: Posts updated, count:', newPosts.length)
}, { immediate: true })
return {
posts: filteredPosts,
isLoading: feedService?.isLoading ?? ref(false),
error: feedService?.error ?? ref(null),
refreshFeed,
loadFeed
}
}