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