feat: add try-delete post option

This commit is contained in:
codytseng
2025-08-30 14:21:35 +08:00
parent 905ef99e0e
commit 13527a3ca7
21 changed files with 241 additions and 97 deletions

View File

@@ -5,6 +5,7 @@ import {
isReplaceableEvent,
isReplyNoteEvent
} from '@/lib/event'
import { useDeletedEvent } from '@/providers/DeletedEventProvider'
import { useMuteList } from '@/providers/MuteListProvider'
import { useNostr } from '@/providers/NostrProvider'
import { useUserTrust } from '@/providers/UserTrustProvider'
@@ -44,6 +45,7 @@ const NoteList = forwardRef(
const { startLogin } = useNostr()
const { isUserTrusted } = useUserTrust()
const { mutePubkeys } = useMuteList()
const { isEventDeleted } = useDeletedEvent()
const [events, setEvents] = useState<Event[]>([])
const [newEvents, setNewEvents] = useState<Event[]>([])
const [hasMore, setHasMore] = useState<boolean>(true)
@@ -58,6 +60,7 @@ const NoteList = forwardRef(
const idSet = new Set<string>()
return events.slice(0, showCount).filter((evt) => {
if (isEventDeleted(evt)) return false
if (hideReplies && isReplyNoteEvent(evt)) return false
if (hideUntrustedNotes && !isUserTrusted(evt.pubkey)) return false
@@ -68,12 +71,13 @@ const NoteList = forwardRef(
idSet.add(id)
return true
})
}, [events, hideReplies, hideUntrustedNotes, showCount])
}, [events, hideReplies, hideUntrustedNotes, showCount, isEventDeleted])
const filteredNewEvents = useMemo(() => {
const idSet = new Set<string>()
return newEvents.filter((event: Event) => {
if (isEventDeleted(event)) return false
if (hideReplies && isReplyNoteEvent(event)) return false
if (hideUntrustedNotes && !isUserTrusted(event.pubkey)) return false
if (filterMutedNotes && mutePubkeys.includes(event.pubkey)) return false
@@ -87,7 +91,7 @@ const NoteList = forwardRef(
idSet.add(id)
return true
})
}, [newEvents, hideReplies, hideUntrustedNotes, filterMutedNotes, mutePubkeys])
}, [newEvents, hideReplies, hideUntrustedNotes, filterMutedNotes, mutePubkeys, isEventDeleted])
const scrollToTop = (behavior: ScrollBehavior = 'instant') => {
setTimeout(() => {

View File

@@ -6,7 +6,7 @@ import { useFavoriteRelays } from '@/providers/FavoriteRelaysProvider'
import { useMuteList } from '@/providers/MuteListProvider'
import { useNostr } from '@/providers/NostrProvider'
import client from '@/services/client.service'
import { Bell, BellOff, Code, Copy, Link, Mail, SatelliteDish, Server } from 'lucide-react'
import { Bell, BellOff, Code, Copy, Link, Mail, SatelliteDish, Server, Trash2 } from 'lucide-react'
import { Event } from 'nostr-tools'
import { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
@@ -45,7 +45,7 @@ export function useMenuActions({
isSmallScreen
}: UseMenuActionsProps) {
const { t } = useTranslation()
const { pubkey, relayList } = useNostr()
const { pubkey, relayList, attemptDelete } = useNostr()
const { relaySets, favoriteRelays } = useFavoriteRelays()
const { mutePubkeyPublicly, mutePubkeyPrivately, unmutePubkey, mutePubkeys } = useMuteList()
const isMuted = useMemo(() => mutePubkeys.includes(event.pubkey), [mutePubkeys, event])
@@ -235,6 +235,19 @@ export function useMenuActions({
}
}
if (pubkey && event.pubkey === pubkey) {
actions.push({
icon: Trash2,
label: t('Try deleting this note'),
onClick: () => {
closeDrawer()
attemptDelete(event)
},
className: 'text-destructive focus:text-destructive',
separator: true
})
}
return actions
}, [
t,