From 85a4a006fa0b49cdeb1a0ef04e5dc27f7ffe15a6 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 25 Aug 2025 17:25:56 -0500 Subject: [PATCH] Handle removals via shadow --- src/screens/Bookmarks.tsx | 22 +++++++++++++++- .../queries/bookmarks/useBookmarksQuery.ts | 26 +------------------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/screens/Bookmarks.tsx b/src/screens/Bookmarks.tsx index edc44493a5..74edb83049 100644 --- a/src/screens/Bookmarks.tsx +++ b/src/screens/Bookmarks.tsx @@ -16,6 +16,7 @@ import { type NativeStackScreenProps, } from '#/lib/routes/types' import {isIOS} from '#/platform/detection' +import {POST_TOMBSTONE, usePostShadow} from '#/state/cache/post-shadow' import {useBookmarkMutation} from '#/state/queries/bookmarks/useBookmarkMutation' import {useBookmarksQuery} from '#/state/queries/bookmarks/useBookmarksQuery' import {useSetMinimalShellMode} from '#/state/shell' @@ -176,6 +177,19 @@ function BookmarksInner() { ) } +function BookmarkPost({ + hideTopBorder, + post: originalPost, +}: { + hideTopBorder: boolean + post: $Typed +}) { + const post = usePostShadow(originalPost) + if (post === POST_TOMBSTONE) return null + if (!post.viewer?.bookmarked) return null + return +} + function BookmarkNotFound({ hideTopBorder, post, @@ -187,9 +201,11 @@ function BookmarkNotFound({ const {_} = useLingui() const {mutateAsync: bookmark} = useBookmarkMutation() const cleanError = useCleanError() + const [removed, setRemoved] = useState(false) const remove = useCallback(async () => { try { + setRemoved(true) await bookmark({action: 'delete', uri: post.uri}) } catch (e) { const {raw, clean} = cleanError(e) @@ -198,6 +214,8 @@ function BookmarkNotFound({ } }, [post.uri, bookmark, cleanError]) + if (removed) return null + return ( } case 'bookmark': { - return + return ( + + ) } case 'bookmarkNotFound': { return ( diff --git a/src/state/queries/bookmarks/useBookmarksQuery.ts b/src/state/queries/bookmarks/useBookmarksQuery.ts index d4f3a567a8..ff53a48b02 100644 --- a/src/state/queries/bookmarks/useBookmarksQuery.ts +++ b/src/state/queries/bookmarks/useBookmarksQuery.ts @@ -1,13 +1,11 @@ -import {type AppBskyBookmarkGetBookmarks, AppBskyFeedDefs} from '@atproto/api' +import {type AppBskyBookmarkGetBookmarks} from '@atproto/api' import { type InfiniteData, type QueryKey, useInfiniteQuery, } from '@tanstack/react-query' -import {dangerousGetPostShadow} from '#/state/cache/post-shadow' import {useAgent} from '#/state/session' -import * as bsky from '#/types/bsky' export const bookmarksQueryKeyRoot = 'bookmarks' export const createBookmarksQueryKey = () => [bookmarksQueryKeyRoot] @@ -31,27 +29,5 @@ export function useBookmarksQuery() { }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, - select: data => { - return { - ...data, - pages: data.pages.map(page => { - return { - ...page, - bookmarks: page.bookmarks.filter(b => { - if ( - bsky.dangerousIsType( - b.item, - AppBskyFeedDefs.isPostView, - ) - ) { - const shadow = dangerousGetPostShadow(b.item) - if (shadow && !shadow.bookmarked) return false - } - return true - }), - } - }), - } - }, }) }