lbry-desktop/ui/js/selectors/cost_info.js

38 lines
1 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import { createSelector } from "reselect";
import { selectCurrentParams } from "selectors/navigation";
2017-04-28 17:14:44 +02:00
2017-06-06 06:21:55 +02:00
export const _selectState = state => state.costInfo || {};
2017-04-28 17:14:44 +02:00
export const selectAllCostInfoByUri = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.byUri || {}
2017-06-06 06:21:55 +02:00
);
2017-04-28 17:14:44 +02:00
2017-05-15 05:50:59 +02:00
export const selectCostInfoForUri = (state, props) => {
2017-06-06 23:19:12 +02:00
return selectAllCostInfoByUri(state)[props.uri];
2017-06-06 06:21:55 +02:00
};
export const makeSelectCostInfoForUri = () => {
2017-06-06 23:19:12 +02:00
return createSelector(selectCostInfoForUri, costInfo => costInfo);
2017-06-06 06:21:55 +02:00
};
2017-08-22 23:19:33 +02:00
export const selectCostForCurrentPageUri = createSelector(
selectAllCostInfoByUri,
selectCurrentParams,
(costInfo, params) =>
params.uri && costInfo[params.uri] ? costInfo[params.uri].cost : undefined
);
export const selectFetchingCostInfo = createSelector(
_selectState,
2017-06-06 23:19:12 +02:00
state => state.fetching || {}
2017-06-06 06:21:55 +02:00
);
const selectFetchingCostInfoForUri = (state, props) => {
2017-06-06 23:19:12 +02:00
return selectFetchingCostInfo(state)[props.uri];
2017-06-06 06:21:55 +02:00
};
export const makeSelectFetchingCostInfoForUri = () => {
2017-06-06 23:19:12 +02:00
return createSelector(selectFetchingCostInfoForUri, fetching => !!fetching);
2017-06-06 06:21:55 +02:00
};