fix: post feed inconsistency/duplicates
This commit is contained in:
2 files changed
+14
-13
No files matched your search
@@ -23,6 +23,7 @@
|
||||
Icon,
|
||||
} from 'svelte-hero-icons'
|
||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||
import { SvelteSet } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
@@ -50,6 +51,9 @@
|
||||
let hasMore = $state(true)
|
||||
|
||||
const abortLoad = new AbortController()
|
||||
let seenIds = new SvelteSet<number>(
|
||||
feedData.posts.posts.map(post => post.post.id),
|
||||
)
|
||||
|
||||
async function loadMore() {
|
||||
if (!hasMore || loading) return
|
||||
@@ -82,15 +86,14 @@
|
||||
|
||||
hasMore = newPosts.posts.length != 0
|
||||
|
||||
let postIds: number[] = []
|
||||
let duplicates: number[] = []
|
||||
for (const post of newPosts.posts) {
|
||||
if (postIds.includes(post.post.id)) duplicates.push(post.post.id)
|
||||
else postIds.push(post.post.id)
|
||||
}
|
||||
|
||||
feedData.cursor.next = newPosts.next_page
|
||||
feedData.posts.posts.push(...newPosts.posts)
|
||||
feedData.posts.posts.push(
|
||||
...newPosts.posts.filter(post => {
|
||||
if (seenIds.has(post.post.id)) return false
|
||||
seenIds.add(post.post.id)
|
||||
return true
|
||||
}),
|
||||
)
|
||||
|
||||
postFeeds.value[feedId].data = feedData
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { isImage } from '$lib/ui/image.js'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import { onMount, untrack } from 'svelte'
|
||||
import { onMount } from 'svelte'
|
||||
import {
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
@@ -65,10 +65,8 @@
|
||||
|
||||
$effect(() => {
|
||||
if (data.cachedFeed && data.post.value.post_view) {
|
||||
untrack(() => {
|
||||
const { id, index } = data.cachedFeed!
|
||||
postFeeds.value[id].data.posts.posts[index] = data.post.value.post_view
|
||||
})
|
||||
const { id, index } = data.cachedFeed!
|
||||
postFeeds.value[id].data.posts.posts[index] = data.post.value.post_view
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user