Fixes for adding/removing watched/library from library/home

This commit is contained in:
CrissZollo 2025-09-29 22:35:54 +02:00
parent 35ace0214a
commit 04f6a0b6be
3 changed files with 34 additions and 30 deletions

View file

@ -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]);

View file

@ -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';

View file

@ -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}
/>
)}
</View>