mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 12:23:24 +00:00
chore: add uids to download items
This commit is contained in:
@@ -11,8 +11,8 @@ const DownloadsScreen: React.FC = () => {
|
||||
return (
|
||||
<ScreenLayout title="Downloads">
|
||||
<ScrollView>
|
||||
{downloads.map((item, index) => (
|
||||
<DownloadItem key={index} {...item} />
|
||||
{downloads.map((item) => (
|
||||
<DownloadItem key={item.id} {...item} />
|
||||
))}
|
||||
</ScrollView>
|
||||
</ScreenLayout>
|
||||
|
@@ -4,6 +4,7 @@ import * as FileSystem from "expo-file-system";
|
||||
import * as MediaLibrary from "expo-media-library";
|
||||
|
||||
interface DownloadItem {
|
||||
id: string;
|
||||
filename: string;
|
||||
progress: number;
|
||||
speed: number;
|
||||
@@ -40,6 +41,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
|
||||
const startDownload = async (url: string, type: "mp4" | "hls") => {
|
||||
const newDownload: DownloadItem = {
|
||||
id: `download-${Date.now()}-${Math.random().toString(16).slice(2)}`,
|
||||
filename: url.split("/").pop() ?? "unknown",
|
||||
progress: 0,
|
||||
speed: 0,
|
||||
@@ -50,7 +52,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
isFinished: false,
|
||||
};
|
||||
|
||||
setDownloads((currentDownloads) => [newDownload, ...currentDownloads]);
|
||||
setDownloads((currentDownloads) => [newDownload, ...currentDownloads]);
|
||||
|
||||
if (type === "mp4") {
|
||||
await downloadMP4(url);
|
||||
|
Reference in New Issue
Block a user