Browse Source

fix: 🐛

imwald
codytseng 10 months ago
parent
commit
12f5d41811
  1. 16
      src/components/ReplyNoteList/index.tsx
  2. 1
      src/providers/ReplyProvider.tsx

16
src/components/ReplyNoteList/index.tsx

@ -31,7 +31,21 @@ export default function ReplyNoteList({
const { currentIndex } = useSecondaryPage() const { currentIndex } = useSecondaryPage()
const [rootInfo, setRootInfo] = useState<{ id: string; pubkey: string } | undefined>(undefined) const [rootInfo, setRootInfo] = useState<{ id: string; pubkey: string } | undefined>(undefined)
const { repliesMap, addReplies } = useReply() const { repliesMap, addReplies } = useReply()
const replies = useMemo(() => repliesMap.get(event.id)?.events || [], [event.id, repliesMap]) const replies = useMemo(() => {
const replyIdSet = new Set<string>()
const replyEvents: NEvent[] = []
let parentEventIds = [event.id]
while (parentEventIds.length > 0) {
const events = parentEventIds.flatMap((id) => repliesMap.get(id)?.events || [])
events.forEach((evt) => {
if (replyIdSet.has(evt.id)) return
replyIdSet.add(evt.id)
replyEvents.push(evt)
})
parentEventIds = events.map((evt) => evt.id)
}
return replyEvents.sort((a, b) => a.created_at - b.created_at)
}, [event.id, repliesMap])
const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined) const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined)
const [until, setUntil] = useState<number | undefined>(undefined) const [until, setUntil] = useState<number | undefined>(undefined)
const [loading, setLoading] = useState<boolean>(false) const [loading, setLoading] = useState<boolean>(false)

1
src/providers/ReplyProvider.tsx

@ -50,7 +50,6 @@ export function ReplyProvider({ children }: { children: React.ReactNode }) {
replies.eventIdSet.add(reply.id) replies.eventIdSet.add(reply.id)
} }
}) })
replies.events.sort((a, b) => a.created_at - b.created_at)
prev.set(id, replies) prev.set(id, replies)
} }
return new Map(prev) return new Map(prev)

Loading…
Cancel
Save