feat: add/remove bookmarks

This commit is contained in:
Adrian Castro
2024-03-26 12:34:30 +01:00
parent e15c76e2b6
commit f296cffb06
5 changed files with 36 additions and 10 deletions

View File

@@ -1,18 +1,17 @@
import React from "react"; import React from "react";
import { View } from "tamagui"; import { View } from "tamagui";
import { import { ItemListSection, watching } from "~/components/item/ItemListSection";
bookmarks,
ItemListSection,
watching,
} from "~/components/item/ItemListSection";
import ScreenLayout from "~/components/layout/ScreenLayout"; import ScreenLayout from "~/components/layout/ScreenLayout";
import { useBookmarkStore } from "~/stores/settings";
export default function HomeScreen() { export default function HomeScreen() {
const { bookmarks } = useBookmarkStore();
return ( return (
<View style={{ flex: 1 }} flex={1}> <View style={{ flex: 1 }} flex={1}>
<ScreenLayout title="Home"> <ScreenLayout title="Home">
<ItemListSection title="Bookmarks" items={bookmarks.concat(watching)} /> <ItemListSection title="Bookmarks" items={bookmarks} />
<ItemListSection <ItemListSection
title="Continue Watching" title="Continue Watching"
items={watching.concat(bookmarks)} items={watching.concat(bookmarks)}

View File

@@ -62,12 +62,14 @@ export default function SettingsScreen() {
toastController.show("Update available", { toastController.show("Update available", {
burntOptions: { preset: "none" }, burntOptions: { preset: "none" },
native: true, native: true,
duration: 500,
}); });
await Linking.openURL(url); await Linking.openURL(url);
} else { } else {
toastController.show("No updates available", { toastController.show("No updates available", {
burntOptions: { preset: "none" }, burntOptions: { preset: "none" },
native: true, native: true,
duration: 500,
}); });
} }
}; };

View File

@@ -7,6 +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";
export interface ItemData { export interface ItemData {
id: string; id: string;
@@ -20,6 +21,7 @@ export default function Item({ data }: { data: ItemData }) {
const resetVideo = usePlayerStore((state) => state.resetVideo); const resetVideo = usePlayerStore((state) => state.resetVideo);
const router = useRouter(); const router = useRouter();
const toastController = useToastController(); const toastController = useToastController();
const { isBookmarked, addBookmark, removeBookmark } = useBookmarkStore();
const { title, type, year, posterUrl } = data; 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 = [ const contextMenuActions = [
{ title: "Bookmark" }, {
...(type === "movie" ? [{ title: "Download" }] : []), title: isBookmarked(data)
? ContextMenuActions.RemoveBookmark
: ContextMenuActions.Bookmark,
},
...(type === "movie" ? [{ title: ContextMenuActions.Download }] : []),
]; ];
const onContextMenuPress = ( const onContextMenuPress = (
e: NativeSyntheticEvent<ContextMenuOnPressNativeEvent>, e: NativeSyntheticEvent<ContextMenuOnPressNativeEvent>,
) => { ) => {
if (e.nativeEvent.name === "Bookmark") { if (e.nativeEvent.name === ContextMenuActions.Bookmark) {
addBookmark(data);
toastController.show("Added to bookmarks", { toastController.show("Added to bookmarks", {
burntOptions: { preset: "done" }, burntOptions: { preset: "done" },
native: true, 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({ router.push({
pathname: "/videoPlayer", pathname: "/videoPlayer",
params: { data: JSON.stringify(data), download: "true" }, params: { data: JSON.stringify(data), download: "true" },

View File

@@ -70,6 +70,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
toastController.show("Download started", { toastController.show("Download started", {
burntOptions: { preset: "none" }, burntOptions: { preset: "none" },
native: true, native: true,
duration: 500,
}); });
const newDownload: DownloadItem = { const newDownload: DownloadItem = {
@@ -187,6 +188,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
toastController.show("Download finished", { toastController.show("Download finished", {
burntOptions: { preset: "done" }, burntOptions: { preset: "done" },
native: true, native: true,
duration: 500,
}); });
return asset; return asset;
} catch (error) { } catch (error) {
@@ -194,6 +196,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
toastController.show("Download failed", { toastController.show("Download failed", {
burntOptions: { preset: "error" }, burntOptions: { preset: "error" },
native: true, native: true,
duration: 500,
}); });
} }
}; };

View File

@@ -31,6 +31,7 @@ const config = {
"import/consistent-type-specifier-style": ["error", "prefer-top-level"], "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-argument": "off", "@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
}, },
ignorePatterns: [ ignorePatterns: [
"**/*.config.js", "**/*.config.js",