mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 16:43:25 +00:00
feat: download history
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import type { ReactNode } from "react";
|
||||
import React, { createContext, useContext, useState } from "react";
|
||||
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||
import * as FileSystem from "expo-file-system";
|
||||
import * as MediaLibrary from "expo-media-library";
|
||||
|
||||
interface DownloadItem {
|
||||
import { loadDownloadHistory, saveDownloadHistory } from "~/settings";
|
||||
|
||||
export interface DownloadItem {
|
||||
id: string;
|
||||
filename: string;
|
||||
progress: number;
|
||||
@@ -39,6 +41,21 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
}) => {
|
||||
const [downloads, setDownloads] = useState<DownloadItem[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const initializeDownloads = async () => {
|
||||
const storedDownloads = await loadDownloadHistory();
|
||||
if (storedDownloads) {
|
||||
setDownloads(storedDownloads);
|
||||
}
|
||||
};
|
||||
|
||||
void initializeDownloads();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void saveDownloadHistory(downloads.slice(0, 10));
|
||||
}, [downloads]);
|
||||
|
||||
const startDownload = async (url: string, type: "mp4" | "hls") => {
|
||||
const newDownload: DownloadItem = {
|
||||
id: `download-${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
||||
|
Reference in New Issue
Block a user