From 78e2b52c138358ecca07de7f0af645e095ddfe34 Mon Sep 17 00:00:00 2001 From: rimar1337 <132627503+rimar1337@users.noreply.github.com> Date: Wed, 22 Oct 2025 15:40:55 +0700 Subject: [PATCH] attempt to prevent feed corruption --- src/components/InfiniteCustomFeed.tsx | 38 ++++++++++++++++++++++----- src/routes/index.tsx | 1 + src/utils/useQuery.ts | 4 +-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/components/InfiniteCustomFeed.tsx b/src/components/InfiniteCustomFeed.tsx index 29ca054..1cbd95c 100644 --- a/src/components/InfiniteCustomFeed.tsx +++ b/src/components/InfiniteCustomFeed.tsx @@ -1,3 +1,4 @@ +import { useQueryClient } from "@tanstack/react-query"; import * as React from "react"; //import { useInView } from "react-intersection-observer"; @@ -37,6 +38,7 @@ export function InfiniteCustomFeed({ isFetchingNextPage, refetch, isRefetching, + queryKey, } = useInfiniteQueryFeedSkeleton({ feedUri: feedUri, agent: agent ?? undefined, @@ -44,11 +46,33 @@ export function InfiniteCustomFeed({ pdsUrl: pdsUrl, feedServiceDid: feedServiceDid, }); + const queryClient = useQueryClient(); + const handleRefresh = () => { + queryClient.removeQueries({queryKey: queryKey}); + //queryClient.invalidateQueries(["infinite-feed", feedUri] as const); refetch(); }; + const allPosts = React.useMemo(() => { + const flattenedPosts = data?.pages.flatMap((page) => page?.feed) ?? []; + + const seenUris = new Set(); + + return flattenedPosts.filter((item) => { + if (!item?.post) return false; + + if (seenUris.has(item.post)) { + return false; + } + + seenUris.add(item.post); + + return true; + }); + }, [data]); + //const { ref, inView } = useInView(); // React.useEffect(() => { @@ -67,10 +91,10 @@ export function InfiniteCustomFeed({ ); } - const allPosts = - data?.pages.flatMap((page) => { - if (page) return page.feed; - }) ?? []; + // const allPosts = + // data?.pages.flatMap((page) => { + // if (page) return page.feed; + // }) ?? []; if (!allPosts || typeof allPosts !== "object" || allPosts.length === 0) { return ( @@ -116,7 +140,9 @@ export function InfiniteCustomFeed({ className="sticky lg:bottom-4 bottom-22 ml-4 w-[42px] h-[42px] z-10 bg-gray-200 dark:bg-gray-800 hover:bg-gray-300 dark:hover:bg-gray-700 text-gray-50 p-[9px] rounded-full shadow-lg transition-transform duration-200 ease-in-out hover:scale-110 disabled:dark:bg-gray-900 disabled:bg-gray-100 disabled:cursor-not-allowed" aria-label="Refresh feed" > - + ); @@ -139,4 +165,4 @@ const RefreshIcon = (props: React.SVGProps) => ( d="M20 11A8.1 8.1 0 0 0 4.5 9M4 5v4h4m-4 4a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" > -); \ No newline at end of file +); diff --git a/src/routes/index.tsx b/src/routes/index.tsx index f5c6484..d113885 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -418,6 +418,7 @@ export function Home({ hidden = false }: { hidden?: boolean }) { {isReadyForAuthedFeed || isReadyForUnauthedFeed ? (