chore: add uids to download items

This commit is contained in:
Adrian Castro
2024-03-20 17:55:26 +01:00
parent f1fc6a9063
commit bc9116237f
2 changed files with 5 additions and 3 deletions

View File

@@ -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>

View File

@@ -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,