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