feat: remove download history items on long press

This commit is contained in:
Adrian Castro
2024-03-20 20:07:23 +01:00
parent fe93b9a92f
commit 66344d552b
3 changed files with 49 additions and 33 deletions

View File

@@ -20,6 +20,7 @@ export interface DownloadItem {
interface DownloadManagerContextType {
downloads: DownloadItem[];
startDownload: (url: string, type: "mp4" | "hls") => Promise<void>;
removeDownload: (id: string) => void;
}
const DownloadManagerContext = createContext<
@@ -168,8 +169,16 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
}
};
const removeDownload = (id: string) => {
const updatedDownloads = downloads.filter((download) => download.id !== id);
setDownloads(updatedDownloads);
void saveDownloadHistory(updatedDownloads);
};
return (
<DownloadManagerContext.Provider value={{ downloads, startDownload }}>
<DownloadManagerContext.Provider
value={{ downloads, startDownload, removeDownload }}
>
{children}
</DownloadManagerContext.Provider>
);