diff --git a/apps/mobile/src/assets/icons.tsx b/apps/mobile/src/assets/icons.tsx index b1c79a34..89d61b17 100644 --- a/apps/mobile/src/assets/icons.tsx +++ b/apps/mobile/src/assets/icons.tsx @@ -386,17 +386,26 @@ export const LikeIcon: React.FC = (props) => { }; export const BookmarkIcon: React.FC = (props) => ( + + + +); + +export const BookmarkFillIcon: React.FC = (props) => ( ); + export const LikeFillIcon: React.FC = (props) => { return ( diff --git a/apps/mobile/src/modules/Post/index.tsx b/apps/mobile/src/modules/Post/index.tsx index f267492e..6bffbc81 100644 --- a/apps/mobile/src/modules/Post/index.tsx +++ b/apps/mobile/src/modules/Post/index.tsx @@ -4,7 +4,7 @@ import {useQueryClient} from '@tanstack/react-query'; import {useProfile, useReact, useReactions, useReplyNotes, useRepost, useBookmark} from 'afk_nostr_sdk'; // import { useAuth } from '../../store/auth'; import {useAuth} from 'afk_nostr_sdk'; -import {useMemo, useState} from 'react'; +import {useEffect, useMemo, useState} from 'react'; import {ActivityIndicator, Image, Pressable, View} from 'react-native'; import Animated, { Easing, @@ -28,10 +28,11 @@ export type PostProps = { asComment?: boolean; event?: NDKEvent; repostedEventProps?:string; - isRepost?:boolean + isRepost?:boolean; + isBookmarked?:boolean; }; -export const Post: React.FC = ({asComment, event, repostedEventProps, isRepost}) => { +export const Post: React.FC = ({asComment, event, repostedEventProps, isRepost, isBookmarked = false}) => { const repostedEvent = repostedEventProps ?? undefined; const {theme} = useTheme(); @@ -50,7 +51,7 @@ export const Post: React.FC = ({asComment, event, repostedEventProps, const react = useReact(); const queryClient = useQueryClient(); const repostMutation = useRepost({ event }); - const { bookmarkNote } = useBookmark(publicKey); + const { bookmarkNote, removeBookmark } = useBookmark(publicKey); const [menuOpen, setMenuOpen] = useState(false); @@ -137,11 +138,16 @@ export const Post: React.FC = ({asComment, event, repostedEventProps, const handleBookmark = async () => { if (!event) return; try { - await bookmarkNote({ event }); - showToast({title: 'Post bookmarked successfully', type: 'success'}); + if (isBookmarked) { + await removeBookmark({ eventId: event.id }); + showToast({ title: 'Post removed from bookmarks', type: 'success' }); + } else { + await bookmarkNote({ event }); + showToast({ title: 'Post bookmarked successfully', type: 'success' }); + } } catch (error) { console.error('Bookmark error:', error); - showToast({title: 'Failed to bookmark', type: 'error'}); + showToast({ title: 'Failed to bookmark', type: 'error' }); } }; @@ -296,7 +302,10 @@ export const Post: React.FC = ({asComment, event, repostedEventProps, style={{marginHorizontal: 3}} onPress={handleBookmark} > - + diff --git a/apps/mobile/src/modules/PostCard/index.tsx b/apps/mobile/src/modules/PostCard/index.tsx index 8d3f8c85..225f8f06 100644 --- a/apps/mobile/src/modules/PostCard/index.tsx +++ b/apps/mobile/src/modules/PostCard/index.tsx @@ -8,9 +8,10 @@ import { useState } from 'react'; export type PostCardProps = { event?: NDKEvent; isRepostProps?:boolean; + isBookmarked?:boolean; }; -export const PostCard: React.FC = ({ event, isRepostProps }) => { +export const PostCard: React.FC = ({ event, isRepostProps, isBookmarked }) => { const styles = useStyles(stylesheet); let repostedEvent = undefined; @@ -21,7 +22,7 @@ export const PostCard: React.FC = ({ event, isRepostProps }) => { } return ( - + ); }; diff --git a/apps/mobile/src/screens/Profile/index.tsx b/apps/mobile/src/screens/Profile/index.tsx index e25f7779..5ca38e6d 100644 --- a/apps/mobile/src/screens/Profile/index.tsx +++ b/apps/mobile/src/screens/Profile/index.tsx @@ -24,6 +24,22 @@ export const Profile: React.FC = ({ route }) => { const reposts = useReposts({ authors: [publicKey] }); const { bookmarksWithNotes } = useBookmark(publicKey); + // Extract all bookmarked note IDs + const bookmarkedNoteIds = useMemo(() => { + if (!bookmarksWithNotes) return new Set(); + + const ids = new Set(); + bookmarksWithNotes.forEach(bookmark => { + bookmark.notes.forEach(note => { + ids.add(note?.id || ''); + }); + }); + return ids; + }, [bookmarksWithNotes]); + + // Function to check if a note is bookmarked + const isBookmarked = (noteId: string) => bookmarkedNoteIds.has(noteId); + const getData = ndkKinds.includes(NDKKind.BookmarkList) || ndkKinds.includes(NDKKind.BookmarkSet) ? bookmarksWithNotes?.map(bookmark => bookmark.notes).flat() || [] : search.data?.pages.flat(); @@ -69,7 +85,7 @@ export const Profile: React.FC = ({ route }) => { const itemReposted = JSON.parse(item?.content); return } - return + return }} refreshControl={ search.refetch()} />