create a media download selector
This commit is contained in:
parent
154deb62ac
commit
f136dfb03c
|
@ -2,7 +2,7 @@ import { Action } from 'redux';
|
|||
import { DownloadResumable } from 'expo-file-system';
|
||||
|
||||
import { MEDIA_DOWNLOAD } from './actionsTypes';
|
||||
import { MediaTypes } from '../lib/methods/handleMediaDownload';
|
||||
import { MediaTypes, mediaDownloadKey } from '../lib/methods/handleMediaDownload';
|
||||
|
||||
interface IMediaDownloadInProgressAction extends Action {
|
||||
key: string;
|
||||
|
@ -26,14 +26,12 @@ interface IMediaDownloadRemove {
|
|||
messageId: string;
|
||||
}
|
||||
|
||||
const downloadKey = (mediaType: MediaTypes, messageId: string) => `${mediaType}-${messageId}`;
|
||||
|
||||
export const mediaDownloadInProgress = ({
|
||||
mediaType,
|
||||
messageId,
|
||||
downloadResumable
|
||||
}: IMediaDownloadInprogress): IMediaDownloadInProgressAction => {
|
||||
const key = downloadKey(mediaType, messageId);
|
||||
const key = mediaDownloadKey(mediaType, messageId);
|
||||
|
||||
return {
|
||||
type: MEDIA_DOWNLOAD.IN_PROGRESS,
|
||||
|
@ -43,7 +41,7 @@ export const mediaDownloadInProgress = ({
|
|||
};
|
||||
|
||||
export const mediaDownloadRemove = ({ mediaType, messageId }: IMediaDownloadRemove): IMediaDownloadRemoveAction => {
|
||||
const key = downloadKey(mediaType, messageId);
|
||||
const key = mediaDownloadKey(mediaType, messageId);
|
||||
|
||||
return {
|
||||
type: MEDIA_DOWNLOAD.REMOVE,
|
||||
|
|
|
@ -22,6 +22,8 @@ const defaultType = {
|
|||
[MediaTypes.video]: 'mp4'
|
||||
};
|
||||
|
||||
export const mediaDownloadKey = (mediaType: MediaTypes, messageId: string) => `${mediaType}-${messageId}`;
|
||||
|
||||
export const LOCAL_DOCUMENT_PATH = `${FileSystem.documentDirectory}`;
|
||||
|
||||
const sanitizeString = (value: string) => sanitizeLikeString(value.substring(value.lastIndexOf('/') + 1));
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import { createSelector } from 'reselect';
|
||||
|
||||
import { IApplicationState } from '../definitions';
|
||||
import { MediaTypes, mediaDownloadKey } from '../lib/methods/handleMediaDownload';
|
||||
import { IDownloads } from '../reducers/mediaDownload';
|
||||
|
||||
const selectMediaDownload = (state: IApplicationState) => state.mediaDownload;
|
||||
|
||||
const getMediaDownload = (mediaDownload: IDownloads, { mediaType, messageId }: { mediaType: MediaTypes; messageId: string }) => {
|
||||
console.log('🚀 ~ file: mediaDownload.ts:10 ~ getMediaDownload ~ { mediaType, messageId }:', { mediaType, messageId });
|
||||
console.log('🚀 ~ file: mediaDownload.ts:10 ~ getMediaDownload ~ mediaDownload:', mediaDownload);
|
||||
const key = mediaDownloadKey(mediaType, messageId);
|
||||
if (mediaDownload[key]) return mediaDownload[key];
|
||||
return null;
|
||||
};
|
||||
|
||||
export const getDownloadResumable = createSelector(
|
||||
[
|
||||
selectMediaDownload,
|
||||
(_state: IApplicationState, { mediaType, messageId }: { mediaType: MediaTypes; messageId: string }) => ({
|
||||
mediaType,
|
||||
messageId
|
||||
})
|
||||
],
|
||||
getMediaDownload
|
||||
);
|
Loading…
Reference in New Issue