diff --git a/src/core/di-container.ts b/src/core/di-container.ts index 72c4926..83525c1 100644 --- a/src/core/di-container.ts +++ b/src/core/di-container.ts @@ -135,6 +135,7 @@ export const SERVICE_TOKENS = { // Feed services FEED_SERVICE: Symbol('feedService'), PROFILE_SERVICE: Symbol('profileService'), + REACTION_SERVICE: Symbol('reactionService'), // Events services EVENTS_SERVICE: Symbol('eventsService'), diff --git a/src/modules/nostr-feed/components/NostrFeed.vue b/src/modules/nostr-feed/components/NostrFeed.vue index 211cf74..d453ef1 100644 --- a/src/modules/nostr-feed/components/NostrFeed.vue +++ b/src/modules/nostr-feed/components/NostrFeed.vue @@ -6,6 +6,7 @@ import { formatDistanceToNow } from 'date-fns' import { Megaphone, RefreshCw, AlertCircle, Reply, Heart, Share } from 'lucide-vue-next' import { useFeed } from '../composables/useFeed' import { useProfiles } from '../composables/useProfiles' +import { useReactions } from '../composables/useReactions' import appConfig from '@/app.config' import type { ContentFilter } from '../services/FeedService' import MarketProduct from './MarketProduct.vue' @@ -39,11 +40,20 @@ const { posts: notes, isLoading, error, refreshFeed } = useFeed({ // Use profiles service for display names const { getDisplayName, fetchProfiles } = useProfiles() -// Watch for new posts and fetch their profiles +// Use reactions service for likes/hearts +const { getEventReactions, subscribeToReactions, toggleLike } = useReactions() + +// Watch for new posts and fetch their profiles and reactions watch(notes, async (newNotes) => { if (newNotes.length > 0) { const pubkeys = [...new Set(newNotes.map(note => note.pubkey))] - await fetchProfiles(pubkeys) + const eventIds = newNotes.map(note => note.id) + + // Fetch profiles and subscribe to reactions in parallel + await Promise.all([ + fetchProfiles(pubkeys), + subscribeToReactions(eventIds) + ]) } }, { immediate: true }) @@ -118,6 +128,15 @@ function onReplyToNote(note: any) { pubkey: note.pubkey }) } + +// Handle like/heart reaction toggle +async function onToggleLike(note: any) { + try { + await toggleLike(note.id, note.pubkey, note.kind) + } catch (error) { + console.error('Failed to toggle like:', error) + } +}