From f296cffb06dacc2376f61145eab11c1820bb082d Mon Sep 17 00:00:00 2001 From: Adrian Castro <22133246+castdrian@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:34:30 +0100 Subject: [PATCH] feat: add/remove bookmarks --- apps/expo/src/app/(tabs)/index.tsx | 11 ++++--- apps/expo/src/app/(tabs)/settings.tsx | 2 ++ apps/expo/src/components/item/item.tsx | 29 ++++++++++++++++--- .../expo/src/hooks/DownloadManagerContext.tsx | 3 ++ tooling/eslint/base.js | 1 + 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/apps/expo/src/app/(tabs)/index.tsx b/apps/expo/src/app/(tabs)/index.tsx index 63a7c78..63359e6 100644 --- a/apps/expo/src/app/(tabs)/index.tsx +++ b/apps/expo/src/app/(tabs)/index.tsx @@ -1,18 +1,17 @@ import React from "react"; import { View } from "tamagui"; -import { - bookmarks, - ItemListSection, - watching, -} from "~/components/item/ItemListSection"; +import { ItemListSection, watching } from "~/components/item/ItemListSection"; import ScreenLayout from "~/components/layout/ScreenLayout"; +import { useBookmarkStore } from "~/stores/settings"; export default function HomeScreen() { + const { bookmarks } = useBookmarkStore(); + return ( - + state.resetVideo); const router = useRouter(); const toastController = useToastController(); + const { isBookmarked, addBookmark, removeBookmark } = useBookmarkStore(); const { title, type, year, posterUrl } = data; @@ -32,20 +34,39 @@ export default function Item({ data }: { data: ItemData }) { }); }; + enum ContextMenuActions { + Bookmark = "Bookmark", + RemoveBookmark = "Remove Bookmark", + Download = "Download", + } + const contextMenuActions = [ - { title: "Bookmark" }, - ...(type === "movie" ? [{ title: "Download" }] : []), + { + title: isBookmarked(data) + ? ContextMenuActions.RemoveBookmark + : ContextMenuActions.Bookmark, + }, + ...(type === "movie" ? [{ title: ContextMenuActions.Download }] : []), ]; const onContextMenuPress = ( e: NativeSyntheticEvent, ) => { - if (e.nativeEvent.name === "Bookmark") { + if (e.nativeEvent.name === ContextMenuActions.Bookmark) { + addBookmark(data); toastController.show("Added to bookmarks", { burntOptions: { preset: "done" }, native: true, + duration: 500, }); - } else if (e.nativeEvent.name === "Download") { + } else if (e.nativeEvent.name === ContextMenuActions.RemoveBookmark) { + removeBookmark(data); + toastController.show("Removed from bookmarks", { + burntOptions: { preset: "done" }, + native: true, + duration: 500, + }); + } else if (e.nativeEvent.name === ContextMenuActions.Download) { router.push({ pathname: "/videoPlayer", params: { data: JSON.stringify(data), download: "true" }, diff --git a/apps/expo/src/hooks/DownloadManagerContext.tsx b/apps/expo/src/hooks/DownloadManagerContext.tsx index b0ac839..a1c78bf 100644 --- a/apps/expo/src/hooks/DownloadManagerContext.tsx +++ b/apps/expo/src/hooks/DownloadManagerContext.tsx @@ -70,6 +70,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ toastController.show("Download started", { burntOptions: { preset: "none" }, native: true, + duration: 500, }); const newDownload: DownloadItem = { @@ -187,6 +188,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ toastController.show("Download finished", { burntOptions: { preset: "done" }, native: true, + duration: 500, }); return asset; } catch (error) { @@ -194,6 +196,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ toastController.show("Download failed", { burntOptions: { preset: "error" }, native: true, + duration: 500, }); } }; diff --git a/tooling/eslint/base.js b/tooling/eslint/base.js index 0241486..8c54454 100644 --- a/tooling/eslint/base.js +++ b/tooling/eslint/base.js @@ -31,6 +31,7 @@ const config = { "import/consistent-type-specifier-style": ["error", "prefer-top-level"], "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unsafe-argument": "off", + "@typescript-eslint/no-unsafe-enum-comparison": "off", }, ignorePatterns: [ "**/*.config.js",