mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-02 05:34:44 +00:00
Fixes for adding/removing watched/library from library/home
This commit is contained in:
parent
35ace0214a
commit
04f6a0b6be
3 changed files with 34 additions and 30 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||||
import { toast } from '@backpackapp-io/react-native-toast';
|
import { toast } from '@backpackapp-io/react-native-toast';
|
||||||
import { DeviceEventEmitter } from 'react-native';
|
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 { Image as ExpoImage } from 'expo-image';
|
||||||
import { MaterialIcons } from '@expo/vector-icons';
|
import { MaterialIcons } from '@expo/vector-icons';
|
||||||
import { useTheme } from '../../contexts/ThemeContext';
|
import { useTheme } from '../../contexts/ThemeContext';
|
||||||
|
|
@ -143,9 +143,16 @@ const ContentItem = ({ item, onPress, shouldLoadImage: shouldLoadImageProp, defe
|
||||||
}
|
}
|
||||||
case 'playlist':
|
case 'playlist':
|
||||||
break;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, [item, inLibrary]);
|
}, [item, inLibrary]);
|
||||||
|
|
||||||
const handleMenuClose = useCallback(() => {
|
const handleMenuClose = useCallback(() => {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ export const DropUpMenu = ({ visible, onClose, item, onOptionSelect, isSaved: is
|
||||||
let menuOptions = [
|
let menuOptions = [
|
||||||
{
|
{
|
||||||
icon: 'bookmark',
|
icon: 'bookmark',
|
||||||
label: 'Remove from Library',
|
label: isSaved ? 'Remove from Library' : 'Add to Library',
|
||||||
action: '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) {
|
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';
|
const backgroundColor = isDarkMode ? '#1A1A1A' : '#FFFFFF';
|
||||||
|
|
|
||||||
|
|
@ -995,29 +995,12 @@ const LibraryScreen = () => {
|
||||||
onClose={() => setMenuVisible(false)}
|
onClose={() => setMenuVisible(false)}
|
||||||
item={selectedItem}
|
item={selectedItem}
|
||||||
isWatched={!!selectedItem.watched}
|
isWatched={!!selectedItem.watched}
|
||||||
|
isSaved={true} // Since this is from library, it's always saved
|
||||||
onOptionSelect={async (option) => {
|
onOptionSelect={async (option) => {
|
||||||
if (!selectedItem) return;
|
if (!selectedItem) return;
|
||||||
if (option === 'share') {
|
switch (option) {
|
||||||
let url = '';
|
case 'library': {
|
||||||
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 || '';
|
|
||||||
}
|
|
||||||
try {
|
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);
|
await catalogService.removeFromLibrary(selectedItem.type, selectedItem.id);
|
||||||
toast('Removed from Library', { duration: 1200 });
|
toast('Removed from Library', { duration: 1200 });
|
||||||
setLibraryItems(prev => prev.filter(item => !(item.id === selectedItem.id && item.type === selectedItem.type)));
|
setLibraryItems(prev => prev.filter(item => !(item.id === selectedItem.id && item.type === selectedItem.type)));
|
||||||
|
|
@ -1025,7 +1008,9 @@ const LibraryScreen = () => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast('Failed to update Library', { duration: 1200 });
|
toast('Failed to update Library', { duration: 1200 });
|
||||||
}
|
}
|
||||||
} else if (option === 'watched') {
|
break;
|
||||||
|
}
|
||||||
|
case 'watched': {
|
||||||
try {
|
try {
|
||||||
// Use AsyncStorage to store watched status by key
|
// Use AsyncStorage to store watched status by key
|
||||||
const key = `watched:${selectedItem.type}:${selectedItem.id}`;
|
const key = `watched:${selectedItem.type}:${selectedItem.id}`;
|
||||||
|
|
@ -1041,9 +1026,21 @@ const LibraryScreen = () => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast('Failed to update watched status', { duration: 1200 });
|
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>
|
</View>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue