mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:33:26 +00:00
rework downloads
This commit is contained in:
@@ -10,12 +10,14 @@ 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 "~/contexts/DownloadManagerContext";
|
||||
import { useDownloadManager } from "~/hooks/useDownloadManager";
|
||||
import { PlayerStatus } from "~/stores/player/slices/interface";
|
||||
import { usePlayerStore } from "~/stores/player/store";
|
||||
import { useDownloadHistoryStore } from "~/stores/settings";
|
||||
|
||||
const DownloadsScreen: React.FC = () => {
|
||||
const { startDownload, downloads } = useDownloadManager();
|
||||
const { startDownload } = useDownloadManager();
|
||||
const downloads = useDownloadHistoryStore((state) => state.downloads);
|
||||
const resetVideo = usePlayerStore((state) => state.resetVideo);
|
||||
const setVideoSrc = usePlayerStore((state) => state.setVideoSrc);
|
||||
const setIsLocalFile = usePlayerStore((state) => state.setIsLocalFile);
|
||||
@@ -106,7 +108,10 @@ const DownloadsScreen: React.FC = () => {
|
||||
await startDownload(
|
||||
"http://sample.vodobox.com/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8",
|
||||
"hls",
|
||||
exampleShowMedia,
|
||||
{
|
||||
...exampleShowMedia,
|
||||
tmdbId: "123456",
|
||||
},
|
||||
).catch(console.error);
|
||||
}}
|
||||
>
|
||||
@@ -118,13 +123,17 @@ const DownloadsScreen: React.FC = () => {
|
||||
gap: "$4",
|
||||
}}
|
||||
>
|
||||
{downloads.map((item) => (
|
||||
<DownloadItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
onPress={() => handlePress(item.localPath)}
|
||||
/>
|
||||
))}
|
||||
{/* TODO: Differentiate movies/shows, shows in new page */}
|
||||
{downloads
|
||||
.map((item) => item.downloads)
|
||||
.flat()
|
||||
.map((item) => (
|
||||
<DownloadItem
|
||||
key={item.id}
|
||||
item={item}
|
||||
onPress={() => handlePress(item.localPath)}
|
||||
/>
|
||||
))}
|
||||
</ScrollView>
|
||||
</ScreenLayout>
|
||||
);
|
||||
|
@@ -11,7 +11,6 @@ import {
|
||||
MaterialCommunityIcons,
|
||||
MaterialIcons,
|
||||
} from "@expo/vector-icons";
|
||||
import { useToastController } from "@tamagui/toast";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import {
|
||||
Adapt,
|
||||
@@ -32,6 +31,7 @@ import { MWButton } from "~/components/ui/Button";
|
||||
import { MWSelect } from "~/components/ui/Select";
|
||||
import { MWSeparator } from "~/components/ui/Separator";
|
||||
import { MWSwitch } from "~/components/ui/Switch";
|
||||
import { useToast } from "~/hooks/useToast";
|
||||
import { checkForUpdate } from "~/lib/update";
|
||||
import {
|
||||
useNetworkSettingsStore,
|
||||
@@ -54,10 +54,10 @@ export default function SettingsScreen() {
|
||||
const { gestureControls, setGestureControls, autoPlay, setAutoPlay } =
|
||||
usePlayerSettingsStore();
|
||||
const { allowMobileData, setAllowMobileData } = useNetworkSettingsStore();
|
||||
const toastController = useToastController();
|
||||
const [showUpdateSheet, setShowUpdateSheet] = useState(false);
|
||||
const [updateMarkdownContent, setUpdateMarkdownContent] = useState("");
|
||||
const [downloadUrl, setDownloadUrl] = useState("");
|
||||
const { showToast } = useToast();
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationKey: ["checkForUpdate"],
|
||||
@@ -74,11 +74,7 @@ export default function SettingsScreen() {
|
||||
);
|
||||
setShowUpdateSheet(true);
|
||||
} else {
|
||||
toastController.show("No updates available", {
|
||||
burntOptions: { preset: "none" },
|
||||
native: true,
|
||||
duration: 500,
|
||||
});
|
||||
showToast("No updates available");
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -100,18 +96,13 @@ export default function SettingsScreen() {
|
||||
|
||||
try {
|
||||
await FileSystem.deleteAsync(cacheDirectory, { idempotent: true });
|
||||
|
||||
toastController.show("Cache cleared", {
|
||||
showToast("Cache cleared", {
|
||||
burntOptions: { preset: "done" },
|
||||
native: true,
|
||||
duration: 500,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error clearing cache directory:", error);
|
||||
toastController.show("Error clearing cache", {
|
||||
showToast("Error clearing cache", {
|
||||
burntOptions: { preset: "error" },
|
||||
native: true,
|
||||
duration: 500,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@@ -10,7 +10,6 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { TamaguiProvider, Theme, useTheme } from "tamagui";
|
||||
import tamaguiConfig from "tamagui.config";
|
||||
|
||||
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";
|
||||
@@ -106,13 +105,11 @@ function RootLayoutNav() {
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<TamaguiProvider config={tamaguiConfig} defaultTheme="main">
|
||||
<ToastProvider>
|
||||
<DownloadManagerProvider>
|
||||
<ThemeProvider value={DarkTheme}>
|
||||
<Theme name={themeStore}>
|
||||
<ScreenStacks />
|
||||
</Theme>
|
||||
</ThemeProvider>
|
||||
</DownloadManagerProvider>
|
||||
<ThemeProvider value={DarkTheme}>
|
||||
<Theme name={themeStore}>
|
||||
<ScreenStacks />
|
||||
</Theme>
|
||||
</ThemeProvider>
|
||||
<ToastViewport />
|
||||
</ToastProvider>
|
||||
</TamaguiProvider>
|
||||
|
Reference in New Issue
Block a user