mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:33:26 +00:00
feat: context menu for watchhistory items
This commit is contained in:
@@ -7,7 +7,7 @@ import { useToastController } from "@tamagui/toast";
|
|||||||
import { Image, Text, View } from "tamagui";
|
import { Image, Text, View } from "tamagui";
|
||||||
|
|
||||||
import { usePlayerStore } from "~/stores/player/store";
|
import { usePlayerStore } from "~/stores/player/store";
|
||||||
import { useBookmarkStore } from "~/stores/settings";
|
import { useBookmarkStore, useWatchHistoryStore } from "~/stores/settings";
|
||||||
|
|
||||||
export interface ItemData {
|
export interface ItemData {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -22,6 +22,8 @@ export default function Item({ data }: { data: ItemData }) {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const toastController = useToastController();
|
const toastController = useToastController();
|
||||||
const { isBookmarked, addBookmark, removeBookmark } = useBookmarkStore();
|
const { isBookmarked, addBookmark, removeBookmark } = useBookmarkStore();
|
||||||
|
const { hasWatchHistoryItem, removeFromWatchHistory } =
|
||||||
|
useWatchHistoryStore();
|
||||||
|
|
||||||
const { title, type, year, posterUrl } = data;
|
const { title, type, year, posterUrl } = data;
|
||||||
|
|
||||||
@@ -38,6 +40,7 @@ export default function Item({ data }: { data: ItemData }) {
|
|||||||
Bookmark = "Bookmark",
|
Bookmark = "Bookmark",
|
||||||
RemoveBookmark = "Remove Bookmark",
|
RemoveBookmark = "Remove Bookmark",
|
||||||
Download = "Download",
|
Download = "Download",
|
||||||
|
RemoveWatchHistoryItem = "Remove from Continue Watching",
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextMenuActions = [
|
const contextMenuActions = [
|
||||||
@@ -47,6 +50,9 @@ export default function Item({ data }: { data: ItemData }) {
|
|||||||
: ContextMenuActions.Bookmark,
|
: ContextMenuActions.Bookmark,
|
||||||
},
|
},
|
||||||
...(type === "movie" ? [{ title: ContextMenuActions.Download }] : []),
|
...(type === "movie" ? [{ title: ContextMenuActions.Download }] : []),
|
||||||
|
...(hasWatchHistoryItem(data)
|
||||||
|
? [{ title: ContextMenuActions.RemoveWatchHistoryItem }]
|
||||||
|
: []),
|
||||||
];
|
];
|
||||||
|
|
||||||
const onContextMenuPress = (
|
const onContextMenuPress = (
|
||||||
@@ -71,6 +77,15 @@ export default function Item({ data }: { data: ItemData }) {
|
|||||||
pathname: "/videoPlayer",
|
pathname: "/videoPlayer",
|
||||||
params: { data: JSON.stringify(data), download: "true" },
|
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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -141,6 +141,7 @@ interface WatchHistoryItem {
|
|||||||
|
|
||||||
interface WatchHistoryStoreState {
|
interface WatchHistoryStoreState {
|
||||||
watchHistory: WatchHistoryItem[];
|
watchHistory: WatchHistoryItem[];
|
||||||
|
hasWatchHistoryItem: (item: ItemData) => boolean;
|
||||||
getWatchHistorItem: (media: ScrapeMedia) => WatchHistoryItem | undefined;
|
getWatchHistorItem: (media: ScrapeMedia) => WatchHistoryItem | undefined;
|
||||||
setWatchHistory: (watchHistory: WatchHistoryItem[]) => void;
|
setWatchHistory: (watchHistory: WatchHistoryItem[]) => void;
|
||||||
updateWatchHistory: (
|
updateWatchHistory: (
|
||||||
@@ -158,6 +159,12 @@ export const useWatchHistoryStore = create<
|
|||||||
persist(
|
persist(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
watchHistory: [],
|
watchHistory: [],
|
||||||
|
hasWatchHistoryItem: (item: ItemData) =>
|
||||||
|
Boolean(
|
||||||
|
get().watchHistory.find(
|
||||||
|
(historyItem) => historyItem.item.id === item.id,
|
||||||
|
),
|
||||||
|
),
|
||||||
getWatchHistorItem: (media: ScrapeMedia) =>
|
getWatchHistorItem: (media: ScrapeMedia) =>
|
||||||
get().watchHistory.find((historyItem) => {
|
get().watchHistory.find((historyItem) => {
|
||||||
if (historyItem.media.type === "movie" && media.type === "movie") {
|
if (historyItem.media.type === "movie" && media.type === "movie") {
|
||||||
|
Reference in New Issue
Block a user