Allow for retring individual tracks
This commit is contained in:
@@ -26,7 +26,7 @@ export const downloadTrack = createAsyncThunk(
|
||||
// Actually kick off the download
|
||||
const { promise } = await downloadFile({
|
||||
fromUrl: url,
|
||||
progressInterval: 50,
|
||||
progressInterval: 250,
|
||||
background: true,
|
||||
begin: ({ jobId, contentLength }) => {
|
||||
// Dispatch the initialization
|
||||
|
||||
@@ -2,12 +2,28 @@ import { createSelector, EntityId } from '@reduxjs/toolkit';
|
||||
import { intersection } from 'lodash';
|
||||
import { AppState } from 'store';
|
||||
|
||||
export const selectAllDownloads = (state: AppState) => state.downloads;
|
||||
export const selectDownloadedEntities = (state: AppState) => state.downloads.entities;
|
||||
|
||||
/**
|
||||
* Only retain the supplied trackIds that have successfully been downloaded
|
||||
*/
|
||||
export const selectDownloadedTracks = (trackIds: EntityId[]) => (
|
||||
createSelector(
|
||||
(state: AppState) => state.downloads,
|
||||
selectAllDownloads,
|
||||
({ entities, ids }) => {
|
||||
return intersection(trackIds, ids)
|
||||
.filter((id) => entities[id]?.isComplete);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Select a boolean that indicates whether the track is downloaded
|
||||
*/
|
||||
export const selectIsDownloaded = (trackId: string) => (
|
||||
createSelector(
|
||||
selectDownloadedEntities,
|
||||
(entities) => entities[trackId]?.isComplete,
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user