diff --git a/src/components/ComposeBox.tsx b/src/components/ComposeBox.tsx index f6f7aad2..ac7a01c7 100644 --- a/src/components/ComposeBox.tsx +++ b/src/components/ComposeBox.tsx @@ -860,9 +860,11 @@ export function ComposeBox({ queryClient.invalidateQueries({ queryKey: ['nostr', 'comments'] }); } else { queryClient.invalidateQueries({ queryKey: ['replies', replyTo.id] }); - // Also invalidate NIP-22 comments cache for non-kind-1 events + // Invalidate the event-comments cache used by CommentsSheet if (replyTo.kind !== 1) { - queryClient.invalidateQueries({ queryKey: ['nostr', 'comments'] }); + const dTag = replyTo.tags.find(([n]) => n === 'd')?.[1] ?? ''; + const aTag = `${replyTo.kind}:${replyTo.pubkey}:${dTag}`; + queryClient.invalidateQueries({ queryKey: ['event-comments', aTag] }); } } } diff --git a/src/components/ui/toast.tsx b/src/components/ui/toast.tsx index a8bbf681..5a6dc996 100644 --- a/src/components/ui/toast.tsx +++ b/src/components/ui/toast.tsx @@ -14,7 +14,7 @@ const ToastViewport = React.forwardRef< (['user-repost', eventId ?? '']); const { data } = useQuery({ queryKey: ['user-repost', eventId ?? ''], @@ -37,10 +40,12 @@ export function useRepostStatus(eventId: string | undefined): string | null | un if (events.length === 0) return null; return events[0].id; }, - enabled: !!eventId && !!user, + enabled: !!eventId && !!user && !optimistic, staleTime: 5 * 60 * 1000, gcTime: 10 * 60 * 1000, }); + // Prefer optimistic value, then query result + if (optimistic) return optimistic; return data; } diff --git a/src/pages/VinesFeedPage.tsx b/src/pages/VinesFeedPage.tsx index f157cdc2..5f755f37 100644 --- a/src/pages/VinesFeedPage.tsx +++ b/src/pages/VinesFeedPage.tsx @@ -152,12 +152,6 @@ export function VineHeartButton({ event, label, noBackground }: { event: NostrEv publishEvent( { kind: 7, content: '+', tags: [['e', event.id], ['p', event.pubkey], ['k', String(event.kind)]] }, { - onSuccess: () => { - setTimeout(() => { - queryClient.invalidateQueries({ queryKey: ['event-stats', event.id] }); - queryClient.invalidateQueries({ queryKey: ['event-interactions', event.id] }); - }, 3000); - }, onError: () => { // Revert optimistic updates if (prevStats) { @@ -216,12 +210,6 @@ export function VineRepostButton({ event, label }: { event: NostrEvent; label?: deleteEvent( { eventId: repostEventId, eventKind: repostKind }, { - onSuccess: () => { - setTimeout(() => { - queryClient.invalidateQueries({ queryKey: ['event-stats', event.id] }); - queryClient.invalidateQueries({ queryKey: ['user-repost', event.id] }); - }, 3000); - }, onError: () => { if (prevStats) queryClient.setQueryData(['event-stats', event.id], prevStats); queryClient.setQueryData(['user-repost', event.id], prevRepostStatus); @@ -250,13 +238,6 @@ export function VineRepostButton({ event, label }: { event: NostrEvent; label?: publishEvent( { kind: repostKind, content: '', tags }, { - onSuccess: () => { - setTimeout(() => { - queryClient.invalidateQueries({ queryKey: ['event-stats', event.id] }); - queryClient.invalidateQueries({ queryKey: ['event-interactions', event.id] }); - queryClient.invalidateQueries({ queryKey: ['user-repost', event.id] }); - }, 3000); - }, onError: () => { if (prevStats) queryClient.setQueryData(['event-stats', event.id], prevStats); queryClient.setQueryData(['user-repost', event.id], null);