import { Alert, Linking, Pressable, View } from "react-native"; import { useRouter } from "expo-router"; import { TailwindResolver } from "@/components/TailwindResolver"; import { useToast } from "@/components/ui/Toast"; import { ClipboardList, Globe, Info, Tag, Trash2 } from "lucide-react-native"; import { useDeleteBookmark } from "@karakeep/shared-react/hooks/bookmarks"; import { useWhoAmI } from "@karakeep/shared-react/hooks/users"; import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks"; interface BottomActionsProps { bookmark: ZBookmark; } export default function BottomActions({ bookmark }: BottomActionsProps) { const { toast } = useToast(); const router = useRouter(); const { data: currentUser } = useWhoAmI(); // Check if the current user owns this bookmark const isOwner = currentUser?.id === bookmark.userId; const { mutate: deleteBookmark, isPending: isDeletionPending } = useDeleteBookmark({ onSuccess: () => { router.back(); toast({ message: "The bookmark has been deleted!", showProgress: false, }); }, onError: () => { toast({ message: "Something went wrong", variant: "destructive", showProgress: false, }); }, }); const deleteBookmarkAlert = () => Alert.alert( "Delete bookmark?", "Are you sure you want to delete this bookmark?", [ { text: "Cancel", style: "cancel" }, { text: "Delete", onPress: () => deleteBookmark({ bookmarkId: bookmark.id }), style: "destructive", }, ], ); const actions = [ { id: "lists", icon: ( } /> ), shouldRender: isOwner, onClick: () => router.push(`/dashboard/bookmarks/${bookmark.id}/manage_lists`), disabled: false, }, { id: "tags", icon: ( } /> ), shouldRender: isOwner, onClick: () => router.push(`/dashboard/bookmarks/${bookmark.id}/manage_tags`), disabled: false, }, { id: "open", icon: ( } /> ), shouldRender: true, onClick: () => router.push(`/dashboard/bookmarks/${bookmark.id}/info`), disabled: false, }, { id: "delete", icon: ( } /> ), shouldRender: isOwner, onClick: deleteBookmarkAlert, disabled: isDeletionPending, }, { id: "browser", icon: ( } /> ), shouldRender: bookmark.content.type == BookmarkTypes.LINK, onClick: () => bookmark.content.type == BookmarkTypes.LINK && Linking.openURL(bookmark.content.url), disabled: false, }, ]; return ( {actions.map( (a) => a.shouldRender && ( {a.icon} ), )} ); }