diff --git a/src/components/home/ContentItem.tsx b/src/components/home/ContentItem.tsx index 9e491e45..e7d44c4c 100644 --- a/src/components/home/ContentItem.tsx +++ b/src/components/home/ContentItem.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useCallback, useRef } from 'react'; import { toast } from '@backpackapp-io/react-native-toast'; import { DeviceEventEmitter } from 'react-native'; -import { View, TouchableOpacity, ActivityIndicator, StyleSheet, Dimensions, Platform, Text, Animated } from 'react-native'; +import { View, TouchableOpacity, ActivityIndicator, StyleSheet, Dimensions, Platform, Text, Animated, Share } from 'react-native'; import { Image as ExpoImage } from 'expo-image'; import { MaterialIcons } from '@expo/vector-icons'; import { useTheme } from '../../contexts/ThemeContext'; @@ -143,8 +143,15 @@ const ContentItem = ({ item, onPress, shouldLoadImage: shouldLoadImageProp, defe } case 'playlist': break; - case 'share': + case 'share': { + let url = ''; + if (item.id) { + url = `https://www.imdb.com/title/${item.id}/`; + } + const message = `${item.name}\n${url}`; + Share.share({ message, url, title: item.name }); break; + } } }, [item, inLibrary]); diff --git a/src/components/home/DropUpMenu.tsx b/src/components/home/DropUpMenu.tsx index d75725c2..391630ae 100644 --- a/src/components/home/DropUpMenu.tsx +++ b/src/components/home/DropUpMenu.tsx @@ -95,7 +95,7 @@ export const DropUpMenu = ({ visible, onClose, item, onOptionSelect, isSaved: is let menuOptions = [ { icon: 'bookmark', - label: 'Remove from Library', + label: isSaved ? 'Remove from Library' : 'Add to Library', action: 'library' }, { @@ -115,9 +115,9 @@ export const DropUpMenu = ({ visible, onClose, item, onOptionSelect, isSaved: is } ]; - // If used in LibraryScreen, only show 'Remove from Library' + // If used in LibraryScreen, only show 'Remove from Library' if item is in library if (isSavedProp === true) { - menuOptions = menuOptions.filter(opt => opt.action !== 'library' || opt.label === 'Remove from Library'); + menuOptions = menuOptions.filter(opt => opt.action !== 'library' || isSaved); } const backgroundColor = isDarkMode ? '#1A1A1A' : '#FFFFFF'; diff --git a/src/screens/LibraryScreen.tsx b/src/screens/LibraryScreen.tsx index 71d238a9..7e7d230c 100644 --- a/src/screens/LibraryScreen.tsx +++ b/src/screens/LibraryScreen.tsx @@ -995,29 +995,12 @@ const LibraryScreen = () => { onClose={() => setMenuVisible(false)} item={selectedItem} isWatched={!!selectedItem.watched} + isSaved={true} // Since this is from library, it's always saved onOptionSelect={async (option) => { if (!selectedItem) return; - if (option === 'share') { - let url = ''; - if (selectedItem.imdbId) { - url = `https://www.imdb.com/title/${selectedItem.imdbId}/`; - } else if (selectedItem.traktId) { - url = `https://trakt.tv/${selectedItem.type === 'movie' ? 'movies' : 'shows'}/${selectedItem.traktId}`; - } else { - url = selectedItem.poster || ''; - } + switch (option) { + case 'library': { try { - await Share.share({ - message: `${selectedItem.name}\n${url}`, - url, - title: selectedItem.name, - }); - } catch (error) { - toast('Failed to share', { duration: 1200 }); - } - } else if (option === 'library') { - try { - // Always remove from library in LibraryScreen await catalogService.removeFromLibrary(selectedItem.type, selectedItem.id); toast('Removed from Library', { duration: 1200 }); setLibraryItems(prev => prev.filter(item => !(item.id === selectedItem.id && item.type === selectedItem.type))); @@ -1025,7 +1008,9 @@ const LibraryScreen = () => { } catch (error) { toast('Failed to update Library', { duration: 1200 }); } - } else if (option === 'watched') { + break; + } + case 'watched': { try { // Use AsyncStorage to store watched status by key const key = `watched:${selectedItem.type}:${selectedItem.id}`; @@ -1034,16 +1019,28 @@ const LibraryScreen = () => { toast(newWatched ? 'Marked as Watched' : 'Marked as Unwatched', { duration: 1200 }); // Instantly update local state setLibraryItems(prev => prev.map(item => - item.id === selectedItem.id && item.type === selectedItem.type - ? { ...item, watched: newWatched } - : item + item.id === selectedItem.id && item.type === selectedItem.type + ? { ...item, watched: newWatched } + : item )); } catch (error) { toast('Failed to update watched status', { duration: 1200 }); } + break; + } + case 'share': { + let url = ''; + if (selectedItem.id) { + url = `https://www.imdb.com/title/${selectedItem.id}/`; + } + const message = `${selectedItem.name}\n${url}`; + Share.share({ message, url, title: selectedItem.name }); + break; + } + default: + break; } }} - isSaved={!!selectedItem.inLibrary} /> )}