remove duplicate deduping

This commit is contained in:
austinkelsay 2025-04-28 17:21:00 -05:00
parent fac14d5b77
commit 14d63d7240
No known key found for this signature in database
GPG Key ID: 5A763922E5BA08EE

View File

@ -107,15 +107,11 @@ const useLessons = (ndk, fetchAuthor, lessonIds, pubkey) => {
const events = await ndk.fetchEvents(filter); const events = await ndk.fetchEvents(filter);
const newLessons = []; const newLessons = [];
// Process events without duplicating // Process events (no need to check for duplicates here)
for (const event of events) { for (const event of events) {
const author = await fetchAuthor(event.pubkey); const author = await fetchAuthor(event.pubkey);
const parsedLesson = { ...parseEvent(event), author }; const parsedLesson = { ...parseEvent(event), author };
newLessons.push(parsedLesson);
// Only add if not already in newLessons array
if (!newLessons.some(lesson => lesson.id === parsedLesson.id)) {
newLessons.push(parsedLesson);
}
} }
setLessons(newLessons); setLessons(newLessons);
@ -128,6 +124,7 @@ const useLessons = (ndk, fetchAuthor, lessonIds, pubkey) => {
} }
}, [lessonIds, ndk, fetchAuthor, pubkey]); }, [lessonIds, ndk, fetchAuthor, pubkey]);
// Keep this deduplication logic using Map
useEffect(() => { useEffect(() => {
const newUniqueLessons = Array.from( const newUniqueLessons = Array.from(
new Map(lessons.map(lesson => [lesson.id, lesson])).values() new Map(lessons.map(lesson => [lesson.id, lesson])).values()