feat: context menu for watchhistory items

This commit is contained in:
Adrian Castro
2024-03-27 13:08:56 +01:00
parent 1e653e6540
commit dca49e8563
2 changed files with 23 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ import { useToastController } from "@tamagui/toast";
import { Image, Text, View } from "tamagui";
import { usePlayerStore } from "~/stores/player/store";
import { useBookmarkStore } from "~/stores/settings";
import { useBookmarkStore, useWatchHistoryStore } from "~/stores/settings";
export interface ItemData {
id: string;
@@ -22,6 +22,8 @@ export default function Item({ data }: { data: ItemData }) {
const router = useRouter();
const toastController = useToastController();
const { isBookmarked, addBookmark, removeBookmark } = useBookmarkStore();
const { hasWatchHistoryItem, removeFromWatchHistory } =
useWatchHistoryStore();
const { title, type, year, posterUrl } = data;
@@ -38,6 +40,7 @@ export default function Item({ data }: { data: ItemData }) {
Bookmark = "Bookmark",
RemoveBookmark = "Remove Bookmark",
Download = "Download",
RemoveWatchHistoryItem = "Remove from Continue Watching",
}
const contextMenuActions = [
@@ -47,6 +50,9 @@ export default function Item({ data }: { data: ItemData }) {
: ContextMenuActions.Bookmark,
},
...(type === "movie" ? [{ title: ContextMenuActions.Download }] : []),
...(hasWatchHistoryItem(data)
? [{ title: ContextMenuActions.RemoveWatchHistoryItem }]
: []),
];
const onContextMenuPress = (
@@ -71,6 +77,15 @@ export default function Item({ data }: { data: ItemData }) {
pathname: "/videoPlayer",
params: { data: JSON.stringify(data), download: "true" },
});
} else if (
e.nativeEvent.name === ContextMenuActions.RemoveWatchHistoryItem
) {
removeFromWatchHistory(data);
toastController.show("Removed from Continue Watching", {
burntOptions: { preset: "done" },
native: true,
duration: 500,
});
}
};