lbry-desktop/ui/redux/selectors/livestream.js

43 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-04-23 05:04:11 +02:00
// @flow
import { createSelector } from 'reselect';
import { selectMyClaims, selectPendingClaims } from 'lbry-redux';
const selectState = (state) => state.livestream || {};
// select non-pending claims without sources for given channel
export const makeSelectLivestreamsForChannelId = (channelId: string) =>
createSelector(selectState, selectMyClaims, (livestreamState, myClaims = []) => {
return myClaims
.filter(
(claim) =>
claim.value_type === 'stream' &&
claim.value &&
!claim.value.source &&
claim.confirmations > 0 &&
claim.signing_channel &&
claim.signing_channel.claim_id === channelId
)
.sort((a, b) => b.timestamp - a.timestamp); // newest first
});
2021-04-23 19:11:53 +02:00
export const selectFetchingLivestreams = createSelector(selectState, (state) => state.fetchingById);
2021-06-17 20:55:23 +02:00
export const selectViewersById = createSelector(selectState, (state) => state.viewersById);
2021-04-23 05:04:11 +02:00
export const makeSelectIsFetchingLivestreams = (channelId: string) =>
createSelector(selectFetchingLivestreams, (fetchingLivestreams) => Boolean(fetchingLivestreams[channelId]));
2021-06-17 20:55:23 +02:00
export const makeSelectViewersForId = (channelId: string) =>
createSelector(selectViewersById, (viewers) => viewers[channelId]);
2021-04-23 05:04:11 +02:00
export const makeSelectPendingLivestreamsForChannelId = (channelId: string) =>
createSelector(selectPendingClaims, (pendingClaims) => {
return pendingClaims.filter(
(claim) =>
claim.value_type === 'stream' &&
claim.value &&
!claim.value.source &&
claim.signing_channel &&
claim.signing_channel.claim_id === channelId
);
});