lbry-redux/src/redux/selectors/file.js

37 lines
1 KiB
JavaScript
Raw Normal View History

2019-05-21 20:18:07 +01:00
// @flow
import { createSelector } from 'reselect';
2019-08-02 02:21:28 -04:00
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
2019-05-21 20:18:07 +01:00
type State = { file: FileState };
export const selectState = (state: State): FileState => state.file || {};
export const selectPurchaseUriErrorMessage: (state: State) => string = createSelector(
selectState,
state => state.purchaseUriErrorMessage
);
2019-05-21 20:18:07 +01:00
export const selectFailedPurchaseUris: (state: State) => Array<string> = createSelector(
selectState,
state => state.failedPurchaseUris
);
export const selectPurchasedUris: (state: State) => Array<string> = createSelector(
selectState,
state => state.purchasedUris
);
export const selectLastPurchasedUri: (state: State) => string = createSelector(
selectState,
state =>
state.purchasedUris.length > 0 ? state.purchasedUris[state.purchasedUris.length - 1] : null
);
2019-08-02 02:21:28 -04:00
export const makeSelectStreamingUrlForUri = (uri: string) =>
2019-05-21 20:18:07 +01:00
createSelector(
2019-08-02 02:21:28 -04:00
makeSelectFileInfoForUri(uri),
fileInfo => {
return fileInfo && fileInfo.streaming_url;
}
2019-05-21 20:18:07 +01:00
);