From c61f18941e5d08865b685ec9123c77a26ae07959 Mon Sep 17 00:00:00 2001 From: Jorrin Date: Sat, 6 Apr 2024 16:53:54 +0200 Subject: [PATCH] downloads refactor --- apps/expo/src/app/(tabs)/downloads.tsx | 22 ++- apps/expo/src/app/(tabs)/settings.tsx | 8 +- apps/expo/src/app/_layout.tsx | 2 +- apps/expo/src/app/videoPlayer.tsx | 5 - apps/expo/src/components/BrandPill.tsx | 13 +- apps/expo/src/components/DownloadItem.tsx | 169 ++++++++---------- .../src/components/item/ItemListSection.tsx | 15 +- apps/expo/src/components/item/item.tsx | 4 +- apps/expo/src/components/layout/Header.tsx | 8 +- .../src/components/layout/ScreenLayout.tsx | 12 +- .../src/components/player/BottomControls.tsx | 5 +- .../src/components/player/ControlsOverlay.tsx | 10 +- .../src/components/player/DownloadButton.tsx | 2 +- .../src/components/player/ScraperProcess.tsx | 2 +- .../src/components/player/VideoPlayer.tsx | 19 +- apps/expo/src/components/ui/Progress.tsx | 14 ++ .../DownloadManagerContext.tsx | 41 +++-- apps/expo/src/stores/player/slices/video.ts | 15 +- apps/expo/src/stores/settings/index.ts | 8 +- 19 files changed, 179 insertions(+), 195 deletions(-) create mode 100644 apps/expo/src/components/ui/Progress.tsx rename apps/expo/src/{hooks => contexts}/DownloadManagerContext.tsx (94%) diff --git a/apps/expo/src/app/(tabs)/downloads.tsx b/apps/expo/src/app/(tabs)/downloads.tsx index ab7964d..ff20153 100644 --- a/apps/expo/src/app/(tabs)/downloads.tsx +++ b/apps/expo/src/app/(tabs)/downloads.tsx @@ -1,4 +1,3 @@ -import type { Asset } from "expo-media-library"; import React from "react"; import { Alert, Platform } from "react-native"; import { ScrollView } from "react-native-gesture-handler"; @@ -12,13 +11,16 @@ import type { ScrapeMedia } from "@movie-web/provider-utils"; import { DownloadItem } from "~/components/DownloadItem"; import ScreenLayout from "~/components/layout/ScreenLayout"; import { MWButton } from "~/components/ui/Button"; -import { useDownloadManager } from "~/hooks/DownloadManagerContext"; +import { useDownloadManager } from "~/contexts/DownloadManagerContext"; +import { PlayerStatus } from "~/stores/player/slices/interface"; import { usePlayerStore } from "~/stores/player/store"; const DownloadsScreen: React.FC = () => { const { startDownload, downloads } = useDownloadManager(); const resetVideo = usePlayerStore((state) => state.resetVideo); - const setAsset = usePlayerStore((state) => state.setAsset); + const setVideoSrc = usePlayerStore((state) => state.setVideoSrc); + const setIsLocalFile = usePlayerStore((state) => state.setIsLocalFile); + const setPlayerStatus = usePlayerStore((state) => state.setPlayerStatus); const router = useRouter(); const theme = useTheme(); @@ -39,10 +41,14 @@ const DownloadsScreen: React.FC = () => { }, [router]), ); - const handlePress = (asset?: Asset) => { - if (!asset) return; + const handlePress = (localPath?: string) => { + if (!localPath) return; resetVideo(); - setAsset(asset); + setIsLocalFile(true); + setPlayerStatus(PlayerStatus.READY); + setVideoSrc({ + uri: localPath, + }); router.push({ pathname: "/videoPlayer", }); @@ -112,8 +118,8 @@ const DownloadsScreen: React.FC = () => { {downloads.map((item) => ( handlePress(item.asset)} + item={item} + onPress={() => handlePress(item.localPath)} /> ))} diff --git a/apps/expo/src/app/(tabs)/settings.tsx b/apps/expo/src/app/(tabs)/settings.tsx index 1aa1e03..4adfcb0 100644 --- a/apps/expo/src/app/(tabs)/settings.tsx +++ b/apps/expo/src/app/(tabs)/settings.tsx @@ -118,8 +118,8 @@ export default function SettingsScreen() { return ( - - + + Appearance @@ -181,7 +181,7 @@ export default function SettingsScreen() { - + Allow downloads on mobile data @@ -451,7 +451,7 @@ export function DefaultQualitySelector(props: DefaultQualitySelectorProps) { {...props} > } diff --git a/apps/expo/src/app/_layout.tsx b/apps/expo/src/app/_layout.tsx index 6c1029d..8afc023 100644 --- a/apps/expo/src/app/_layout.tsx +++ b/apps/expo/src/app/_layout.tsx @@ -10,7 +10,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { TamaguiProvider, Theme, useTheme } from "tamagui"; import tamaguiConfig from "tamagui.config"; -import { DownloadManagerProvider } from "~/hooks/DownloadManagerContext"; +import { DownloadManagerProvider } from "~/contexts/DownloadManagerContext"; import { useThemeStore } from "~/stores/theme"; // @ts-expect-error - Without named import it causes an infinite loop import _styles from "../../tamagui-web.css"; diff --git a/apps/expo/src/app/videoPlayer.tsx b/apps/expo/src/app/videoPlayer.tsx index 4c6e31a..e574b0e 100644 --- a/apps/expo/src/app/videoPlayer.tsx +++ b/apps/expo/src/app/videoPlayer.tsx @@ -11,7 +11,6 @@ import { usePlayerStore } from "~/stores/player/store"; export default function VideoPlayerWrapper() { const playerStatus = usePlayerStore((state) => state.interface.playerStatus); - const asset = usePlayerStore((state) => state.asset); const { presentFullscreenPlayer } = usePlayer(); const params = useLocalSearchParams(); @@ -32,10 +31,6 @@ export default function VideoPlayerWrapper() { void presentFullscreenPlayer(); - if (asset) { - return ; - } - if (download) { return ; } diff --git a/apps/expo/src/components/BrandPill.tsx b/apps/expo/src/components/BrandPill.tsx index 5105315..83829ff 100644 --- a/apps/expo/src/components/BrandPill.tsx +++ b/apps/expo/src/components/BrandPill.tsx @@ -10,9 +10,9 @@ export function BrandPill() { flexDirection="row" alignItems="center" justifyContent="center" - paddingHorizontal="$2.5" - paddingVertical="$2" - gap={2} + paddingHorizontal="$3" + paddingVertical="$2.5" + gap="$2.5" opacity={0.8} backgroundColor="$pillBackground" borderRadius={24} @@ -24,11 +24,10 @@ export function BrandPill() { > - - {/* padding might need adjusting */} + movie-web diff --git a/apps/expo/src/components/DownloadItem.tsx b/apps/expo/src/components/DownloadItem.tsx index 4d59ec3..d95e552 100644 --- a/apps/expo/src/components/DownloadItem.tsx +++ b/apps/expo/src/components/DownloadItem.tsx @@ -1,25 +1,17 @@ -import type { Asset } from "expo-media-library"; import type { NativeSyntheticEvent } from "react-native"; import type { ContextMenuOnPressNativeEvent } from "react-native-context-menu-view"; import React from "react"; import ContextMenu from "react-native-context-menu-view"; import { TouchableOpacity } from "react-native-gesture-handler"; -import { Progress, Spinner, Text, View } from "tamagui"; +import { Image, Text, View, XStack, YStack } from "tamagui"; -import { useDownloadManager } from "~/hooks/DownloadManagerContext"; +import type { Download } from "~/contexts/DownloadManagerContext"; +import { useDownloadManager } from "~/contexts/DownloadManagerContext"; +import { MWProgress } from "./ui/Progress"; export interface DownloadItemProps { - id: string; - filename: string; - progress: number; - speed: number; - fileSize: number; - downloaded: number; - isFinished: boolean; - statusText?: string; - asset?: Asset; - isHLS?: boolean; - onPress: (asset?: Asset) => void; + item: Download; + onPress: (localPath?: string) => void; } enum ContextMenuActions { @@ -27,6 +19,15 @@ enum ContextMenuActions { Remove = "Remove", } +const statusToTextMap: Record = { + downloading: "Downloading", + finished: "Finished", + error: "Error", + merging: "Merging", + cancelled: "Cancelled", + importing: "Importing", +}; + const formatBytes = (bytes: number, decimals = 2) => { if (bytes === 0) return "0 Bytes"; const k = 1024; @@ -36,64 +37,28 @@ const formatBytes = (bytes: number, decimals = 2) => { return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i]; }; -export const DownloadItem: React.FC = ({ - id, - filename, - progress, - speed, - fileSize, - downloaded, - isFinished, - statusText, - asset, - isHLS, - onPress, -}) => { - const percentage = progress * 100; - const formattedFileSize = formatBytes(fileSize); - const formattedDownloaded = formatBytes(downloaded); +export function DownloadItem(props: DownloadItemProps) { + const percentage = props.item.progress * 100; + const formattedFileSize = formatBytes(props.item.fileSize); + const formattedDownloaded = formatBytes(props.item.downloaded); const { removeDownload, cancelDownload } = useDownloadManager(); const contextMenuActions = [ { title: ContextMenuActions.Remove, }, - ...(!isFinished ? [{ title: ContextMenuActions.Cancel }] : []), + ...(props.item.status !== "finished" + ? [{ title: ContextMenuActions.Cancel }] + : []), ]; const onContextMenuPress = ( e: NativeSyntheticEvent, ) => { if (e.nativeEvent.name === ContextMenuActions.Cancel) { - void cancelDownload(id); + void cancelDownload(props.item.id); } else if (e.nativeEvent.name === ContextMenuActions.Remove) { - removeDownload(id); - } - }; - - const renderStatus = () => { - if (statusText) { - return ( - - - - {statusText} - - - ); - } else if (isFinished) { - return ( - - Finished - - ); - } else { - if (isHLS) return null; - return ( - - {speed.toFixed(2)} MB/s - - ); + removeDownload(props.item.id); } }; @@ -103,41 +68,63 @@ export const DownloadItem: React.FC = ({ onPress={onContextMenuPress} previewBackgroundColor="transparent" > - onPress(asset)} activeOpacity={0.7}> - - - {filename} - - - - + props.onPress(props.item.localPath)} + onLongPress={() => { + return; + }} + activeOpacity={0.7} + > + - - {isHLS - ? `${percentage.toFixed()}% - ${downloaded} of ${fileSize} segments` - : `${percentage.toFixed()}% - ${formattedDownloaded} of ${formattedFileSize}`} - - {renderStatus()} + - + + + + {props.item.media.title} + + {props.item.type !== "hls" && ( + + {props.item.speed.toFixed(2)} MB/s + + )} + + + + + + + {props.item.type === "hls" + ? `${percentage.toFixed()}% - ${props.item.downloaded} of ${props.item.fileSize} segments` + : `${percentage.toFixed()}% - ${formattedDownloaded} of ${formattedFileSize}`} + + + + {statusToTextMap[props.item.status]} + + + + + ); -}; +} diff --git a/apps/expo/src/components/item/ItemListSection.tsx b/apps/expo/src/components/item/ItemListSection.tsx index 35f48c7..5e15392 100644 --- a/apps/expo/src/components/item/ItemListSection.tsx +++ b/apps/expo/src/components/item/ItemListSection.tsx @@ -18,21 +18,12 @@ export const ItemListSection = ({ }) => { return ( - + {title} - + {items.map((item, index) => ( - + ))} diff --git a/apps/expo/src/components/item/item.tsx b/apps/expo/src/components/item/item.tsx index 9d26840..408331d 100644 --- a/apps/expo/src/components/item/item.tsx +++ b/apps/expo/src/components/item/item.tsx @@ -142,8 +142,8 @@ export default function Item({ data }: { data: ItemData }) { {type === "tv" ? "Show" : "Movie"} diff --git a/apps/expo/src/components/layout/Header.tsx b/apps/expo/src/components/layout/Header.tsx index f82f7ec..5f17a37 100644 --- a/apps/expo/src/components/layout/Header.tsx +++ b/apps/expo/src/components/layout/Header.tsx @@ -21,7 +21,7 @@ export function Header() { - + - + ); diff --git a/apps/expo/src/components/layout/ScreenLayout.tsx b/apps/expo/src/components/layout/ScreenLayout.tsx index fbf8a2e..d04c93c 100644 --- a/apps/expo/src/components/layout/ScreenLayout.tsx +++ b/apps/expo/src/components/layout/ScreenLayout.tsx @@ -1,4 +1,4 @@ -import { View } from "tamagui"; +import { ScrollView } from "tamagui"; import { LinearGradient } from "tamagui/linear-gradient"; import { Header } from "./Header"; @@ -12,7 +12,7 @@ export default function ScreenLayout({ children }: Props) {
- + {children} - + ); } diff --git a/apps/expo/src/components/player/BottomControls.tsx b/apps/expo/src/components/player/BottomControls.tsx index 01439a1..1dd8f30 100644 --- a/apps/expo/src/components/player/BottomControls.tsx +++ b/apps/expo/src/components/player/BottomControls.tsx @@ -14,9 +14,10 @@ import { SettingsSelector } from "./SettingsSelector"; import { SourceSelector } from "./SourceSelector"; import { mapMillisecondsToTime } from "./utils"; -export const BottomControls = ({ isLocalAsset }: { isLocalAsset: boolean }) => { +export const BottomControls = () => { const status = usePlayerStore((state) => state.status); const setIsIdle = usePlayerStore((state) => state.setIsIdle); + const isLocalFile = usePlayerStore((state) => state.isLocalFile); const [showRemaining, setShowRemaining] = useState(false); const toggleTimeDisplay = useCallback(() => { @@ -76,7 +77,7 @@ export const BottomControls = ({ isLocalAsset }: { isLocalAsset: boolean }) => { gap={4} paddingBottom={40} > - {!isLocalAsset && ( + {!isLocalFile && ( <> diff --git a/apps/expo/src/components/player/ControlsOverlay.tsx b/apps/expo/src/components/player/ControlsOverlay.tsx index 720da08..981f47b 100644 --- a/apps/expo/src/components/player/ControlsOverlay.tsx +++ b/apps/expo/src/components/player/ControlsOverlay.tsx @@ -4,13 +4,7 @@ import { BottomControls } from "./BottomControls"; import { Header } from "./Header"; import { MiddleControls } from "./MiddleControls"; -export const ControlsOverlay = ({ - isLoading, - isLocalAsset, -}: { - isLoading: boolean; - isLocalAsset: boolean; -}) => { +export const ControlsOverlay = ({ isLoading }: { isLoading: boolean }) => { return (
{!isLoading && } - + ); }; diff --git a/apps/expo/src/components/player/DownloadButton.tsx b/apps/expo/src/components/player/DownloadButton.tsx index 46605a1..07fec47 100644 --- a/apps/expo/src/components/player/DownloadButton.tsx +++ b/apps/expo/src/components/player/DownloadButton.tsx @@ -3,7 +3,7 @@ import { useTheme } from "tamagui"; import { findHighestQuality } from "@movie-web/provider-utils"; -import { useDownloadManager } from "~/hooks/DownloadManagerContext"; +import { useDownloadManager } from "~/contexts/DownloadManagerContext"; import { convertMetaToScrapeMedia } from "~/lib/meta"; import { usePlayerStore } from "~/stores/player/store"; import { MWButton } from "../ui/Button"; diff --git a/apps/expo/src/components/player/ScraperProcess.tsx b/apps/expo/src/components/player/ScraperProcess.tsx index 619655d..cf74188 100644 --- a/apps/expo/src/components/player/ScraperProcess.tsx +++ b/apps/expo/src/components/player/ScraperProcess.tsx @@ -18,7 +18,7 @@ import { import type { ItemData } from "../item/item"; import type { AudioTrack } from "./AudioTrackSelector"; import type { PlayerMeta } from "~/stores/player/slices/video"; -import { useDownloadManager } from "~/hooks/DownloadManagerContext"; +import { useDownloadManager } from "~/contexts/DownloadManagerContext"; import { useMeta } from "~/hooks/player/useMeta"; import { useScrape } from "~/hooks/player/useSourceScrape"; import { convertMetaToScrapeMedia } from "~/lib/meta"; diff --git a/apps/expo/src/components/player/VideoPlayer.tsx b/apps/expo/src/components/player/VideoPlayer.tsx index 7fd02b0..11e61a3 100644 --- a/apps/expo/src/components/player/VideoPlayer.tsx +++ b/apps/expo/src/components/player/VideoPlayer.tsx @@ -11,7 +11,6 @@ import Animated, { import { useSafeAreaInsets } from "react-native-safe-area-context"; import { ResizeMode, Video } from "expo-av"; import * as Haptics from "expo-haptics"; -import * as MediaLibrary from "expo-media-library"; import * as NavigationBar from "expo-navigation-bar"; import { useRouter } from "expo-router"; import * as StatusBar from "expo-status-bar"; @@ -63,7 +62,6 @@ export const VideoPlayer = () => { const stream = usePlayerStore((state) => state.interface.currentStream); const selectedAudioTrack = useAudioTrackStore((state) => state.selectedTrack); const videoRef = usePlayerStore((state) => state.videoRef); - const asset = usePlayerStore((state) => state.asset); const setVideoRef = usePlayerStore((state) => state.setVideoRef); const videoSrc = usePlayerStore((state) => state.videoSrc) ?? undefined; const setVideoSrc = usePlayerStore((state) => state.setVideoSrc); @@ -73,6 +71,7 @@ export const VideoPlayer = () => { const toggleState = usePlayerStore((state) => state.toggleState); const meta = usePlayerStore((state) => state.meta); const setMeta = usePlayerStore((state) => state.setMeta); + const isLocalFile = usePlayerStore((state) => state.isLocalFile); const { gestureControls, autoPlay } = usePlayerSettingsStore(); const { updateWatchHistory, removeFromWatchHistory, getWatchHistoryItem } = @@ -151,15 +150,7 @@ export const VideoPlayer = () => { useEffect(() => { const initializePlayer = async () => { - if (asset) { - const assetInfo = await MediaLibrary.getAssetInfoAsync(asset); - if (!assetInfo.localUri) return; - setVideoSrc({ - uri: assetInfo.localUri, - }); - setIsLoading(false); - return; - } + if (videoSrc?.uri && isLocalFile) return; if (!stream) { await dismissFullscreenPlayer(); @@ -194,7 +185,6 @@ export const VideoPlayer = () => { setIsLoading(false); }; - setIsLoading(true); void initializePlayer(); const timeout = setTimeout(() => { @@ -217,7 +207,7 @@ export const VideoPlayer = () => { void synchronizePlayback(); }; }, [ - asset, + isLocalFile, dismissFullscreenPlayer, hasStartedPlaying, meta, @@ -228,6 +218,7 @@ export const VideoPlayer = () => { synchronizePlayback, updateWatchHistory, videoRef?.props.positionMillis, + videoSrc?.uri, ]); const onVideoLoadStart = () => { @@ -322,7 +313,7 @@ export const VideoPlayer = () => { position="absolute" /> )} - + {showVolumeOverlay && } {showBrightnessOverlay && ( diff --git a/apps/expo/src/components/ui/Progress.tsx b/apps/expo/src/components/ui/Progress.tsx new file mode 100644 index 0000000..bad6cee --- /dev/null +++ b/apps/expo/src/components/ui/Progress.tsx @@ -0,0 +1,14 @@ +import { Progress, styled, withStaticProperties } from "tamagui"; + +const MWProgressFrame = styled(Progress, { + backgroundColor: "$progressBackground", +}); + +const MWProgressIndicator = styled(Progress.Indicator, { + backgroundColor: "$progressFilled", + animation: "bounce", +}); + +export const MWProgress = withStaticProperties(MWProgressFrame, { + Indicator: MWProgressIndicator, +}); diff --git a/apps/expo/src/hooks/DownloadManagerContext.tsx b/apps/expo/src/contexts/DownloadManagerContext.tsx similarity index 94% rename from apps/expo/src/hooks/DownloadManagerContext.tsx rename to apps/expo/src/contexts/DownloadManagerContext.tsx index 4d14dbc..9156e5f 100644 --- a/apps/expo/src/hooks/DownloadManagerContext.tsx +++ b/apps/expo/src/contexts/DownloadManagerContext.tsx @@ -23,23 +23,31 @@ import { useNetworkSettingsStore, } from "~/stores/settings"; -export interface DownloadItem { +export interface Download { id: string; - filename: string; progress: number; speed: number; fileSize: number; downloaded: number; url: string; type: "mp4" | "hls"; - isFinished: boolean; - statusText?: string; - asset?: Asset; - isHLS?: boolean; + status: + | "downloading" + | "finished" + | "error" + | "merging" + | "cancelled" + | "importing"; + localPath?: string; media: ScrapeMedia; downloadTask?: DownloadTask; } +export interface DownloadContent { + media: Pick; + downloads: Download[]; +} + // @ts-expect-error - types are not up to date setConfig({ isLogsEnabled: false, @@ -47,7 +55,7 @@ setConfig({ }); interface DownloadManagerContextType { - downloads: DownloadItem[]; + downloads: Download[]; startDownload: ( url: string, type: "mp4" | "hls", @@ -75,7 +83,7 @@ export const useDownloadManager = () => { export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ children, }) => { - const [downloads, setDownloads] = useState([]); + const [downloads, setDownloads] = useState([]); const toastController = useToastController(); useEffect(() => { @@ -172,17 +180,15 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ duration: 500, }); - const newDownload: DownloadItem = { + const newDownload: Download = { id: `download-${Date.now()}-${Math.random().toString(16).slice(2)}`, - filename: url.split("/").pop() ?? "unknown", progress: 0, speed: 0, fileSize: 0, downloaded: 0, type, url, - isFinished: false, - isHLS: type === "hls", + status: "downloading", media, }; @@ -197,7 +203,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ } }; - const updateDownloadItem = (id: string, updates: Partial) => { + const updateDownloadItem = (id: string, updates: Partial) => { setDownloads((currentDownloads) => currentDownloads.map((download) => download.id === id ? { ...download, ...updates } : download, @@ -342,7 +348,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ return removeDownload(downloadId); } - updateDownloadItem(downloadId, { statusText: "Merging" }); + updateDownloadItem(downloadId, { status: "merging" }); const uri = await VideoManager.mergeVideos( localSegmentPaths, `${FileSystem.cacheDirectory}movie-web/output.mp4`, @@ -394,15 +400,14 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({ downloadId: string, ): Promise => { try { - updateDownloadItem(downloadId, { statusText: "Importing" }); + updateDownloadItem(downloadId, { status: "importing" }); const asset = await MediaLibrary.createAssetAsync(fileUri); await FileSystem.deleteAsync(fileUri); updateDownloadItem(downloadId, { - statusText: undefined, - asset, - isFinished: true, + status: "finished", + localPath: asset.uri, }); console.log("File saved to media library and original deleted"); toastController.show("Download finished", { diff --git a/apps/expo/src/stores/player/slices/video.ts b/apps/expo/src/stores/player/slices/video.ts index 437d269..c0404ad 100644 --- a/apps/expo/src/stores/player/slices/video.ts +++ b/apps/expo/src/stores/player/slices/video.ts @@ -1,5 +1,4 @@ import type { AVPlaybackSourceObject, AVPlaybackStatus, Video } from "expo-av"; -import type { Asset } from "expo-media-library"; import type { MakeSlice } from "./types"; import { PlayerStatus } from "./interface"; @@ -31,13 +30,13 @@ export interface VideoSlice { videoSrc: AVPlaybackSourceObject | null; status: AVPlaybackStatus | null; meta: PlayerMeta | null; - asset: Asset | null; + isLocalFile: boolean; setVideoRef(ref: Video | null): void; setVideoSrc(src: AVPlaybackSourceObject | null): void; setStatus(status: AVPlaybackStatus | null): void; setMeta(meta: PlayerMeta | null): void; - setAsset(asset: Asset | null): void; + setIsLocalFile(isLocalFile: boolean): void; resetVideo(): void; } @@ -46,7 +45,7 @@ export const createVideoSlice: MakeSlice = (set) => ({ videoSrc: null, status: null, meta: null, - asset: null, + isLocalFile: false, setVideoRef: (ref) => { set({ videoRef: ref }); @@ -67,13 +66,11 @@ export const createVideoSlice: MakeSlice = (set) => ({ s.meta = meta; }); }, - setAsset: (asset) => { - set((s) => { - s.asset = asset; - }); + setIsLocalFile: (isLocalFile) => { + set({ isLocalFile }); }, resetVideo() { - set({ videoRef: null, status: null, meta: null, asset: null }); + set({ videoRef: null, status: null, meta: null, isLocalFile: false }); set((s) => { s.interface.playerStatus = PlayerStatus.SCRAPING; }); diff --git a/apps/expo/src/stores/settings/index.ts b/apps/expo/src/stores/settings/index.ts index 2ca6db7..8a53d38 100644 --- a/apps/expo/src/stores/settings/index.ts +++ b/apps/expo/src/stores/settings/index.ts @@ -7,7 +7,7 @@ import { createJSONStorage, persist } from "zustand/middleware"; import type { ScrapeMedia } from "@movie-web/provider-utils"; import type { ItemData } from "~/components/item/item"; -import type { DownloadItem } from "~/hooks/DownloadManagerContext"; +import type { Download } from "~/contexts/DownloadManagerContext"; import type { ThemeStoreOption } from "~/stores/theme"; const storage = new MMKV(); @@ -77,8 +77,8 @@ export const usePlayerSettingsStore = create< ); interface DownloadHistoryStoreState { - downloads: DownloadItem[]; - setDownloads: (downloads: DownloadItem[]) => void; + downloads: Download[]; + setDownloads: (downloads: Download[]) => void; } export const useDownloadHistoryStore = create< @@ -88,7 +88,7 @@ export const useDownloadHistoryStore = create< persist( (set) => ({ downloads: [], - setDownloads: (downloads: DownloadItem[]) => set({ downloads }), + setDownloads: (downloads: Download[]) => set({ downloads }), }), { name: "download-history",