Handle removals via shadow

This commit is contained in:
Eric Bailey
2025-08-25 17:25:56 -05:00
parent 8c40895fd5
commit 85a4a006fa
2 changed files with 22 additions and 26 deletions
+21 -1
View File
@@ -16,6 +16,7 @@ import {
type NativeStackScreenProps, type NativeStackScreenProps,
} from '#/lib/routes/types' } from '#/lib/routes/types'
import {isIOS} from '#/platform/detection' import {isIOS} from '#/platform/detection'
import {POST_TOMBSTONE, usePostShadow} from '#/state/cache/post-shadow'
import {useBookmarkMutation} from '#/state/queries/bookmarks/useBookmarkMutation' import {useBookmarkMutation} from '#/state/queries/bookmarks/useBookmarkMutation'
import {useBookmarksQuery} from '#/state/queries/bookmarks/useBookmarksQuery' import {useBookmarksQuery} from '#/state/queries/bookmarks/useBookmarksQuery'
import {useSetMinimalShellMode} from '#/state/shell' import {useSetMinimalShellMode} from '#/state/shell'
@@ -176,6 +177,19 @@ function BookmarksInner() {
) )
} }
function BookmarkPost({
hideTopBorder,
post: originalPost,
}: {
hideTopBorder: boolean
post: $Typed<AppBskyFeedDefs.PostView>
}) {
const post = usePostShadow(originalPost)
if (post === POST_TOMBSTONE) return null
if (!post.viewer?.bookmarked) return null
return <Post post={post} hideTopBorder={hideTopBorder} />
}
function BookmarkNotFound({ function BookmarkNotFound({
hideTopBorder, hideTopBorder,
post, post,
@@ -187,9 +201,11 @@ function BookmarkNotFound({
const {_} = useLingui() const {_} = useLingui()
const {mutateAsync: bookmark} = useBookmarkMutation() const {mutateAsync: bookmark} = useBookmarkMutation()
const cleanError = useCleanError() const cleanError = useCleanError()
const [removed, setRemoved] = useState(false)
const remove = useCallback(async () => { const remove = useCallback(async () => {
try { try {
setRemoved(true)
await bookmark({action: 'delete', uri: post.uri}) await bookmark({action: 'delete', uri: post.uri})
} catch (e) { } catch (e) {
const {raw, clean} = cleanError(e) const {raw, clean} = cleanError(e)
@@ -198,6 +214,8 @@ function BookmarkNotFound({
} }
}, [post.uri, bookmark, cleanError]) }, [post.uri, bookmark, cleanError])
if (removed) return null
return ( return (
<View <View
style={[ style={[
@@ -248,7 +266,9 @@ function renderItem({item, index}: {item: ListItem; index: number}) {
return <PostFeedLoadingPlaceholder /> return <PostFeedLoadingPlaceholder />
} }
case 'bookmark': { case 'bookmark': {
return <Post post={item.bookmark.item} hideTopBorder={index === 0} /> return (
<BookmarkPost post={item.bookmark.item} hideTopBorder={index === 0} />
)
} }
case 'bookmarkNotFound': { case 'bookmarkNotFound': {
return ( return (
@@ -1,13 +1,11 @@
import {type AppBskyBookmarkGetBookmarks, AppBskyFeedDefs} from '@atproto/api' import {type AppBskyBookmarkGetBookmarks} from '@atproto/api'
import { import {
type InfiniteData, type InfiniteData,
type QueryKey, type QueryKey,
useInfiniteQuery, useInfiniteQuery,
} from '@tanstack/react-query' } from '@tanstack/react-query'
import {dangerousGetPostShadow} from '#/state/cache/post-shadow'
import {useAgent} from '#/state/session' import {useAgent} from '#/state/session'
import * as bsky from '#/types/bsky'
export const bookmarksQueryKeyRoot = 'bookmarks' export const bookmarksQueryKeyRoot = 'bookmarks'
export const createBookmarksQueryKey = () => [bookmarksQueryKeyRoot] export const createBookmarksQueryKey = () => [bookmarksQueryKeyRoot]
@@ -31,27 +29,5 @@ export function useBookmarksQuery() {
}, },
initialPageParam: undefined, initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor, getNextPageParam: lastPage => lastPage.cursor,
select: data => {
return {
...data,
pages: data.pages.map(page => {
return {
...page,
bookmarks: page.bookmarks.filter(b => {
if (
bsky.dangerousIsType<AppBskyFeedDefs.PostView>(
b.item,
AppBskyFeedDefs.isPostView,
)
) {
const shadow = dangerousGetPostShadow(b.item)
if (shadow && !shadow.bookmarked) return false
}
return true
}),
}
}),
}
},
}) })
} }