2019-09-26 18:28:08 +02:00
|
|
|
import { connect } from 'react-redux';
|
2021-12-02 14:36:53 +01:00
|
|
|
import {
|
|
|
|
selectMyChannelUrls,
|
|
|
|
selectFetchingMyChannels,
|
|
|
|
makeSelectClaimIsPending,
|
|
|
|
selectPendingIds,
|
2022-03-09 19:05:37 +01:00
|
|
|
selectClaimsByUri,
|
2021-12-02 14:36:53 +01:00
|
|
|
} from 'redux/selectors/claims';
|
2022-03-09 19:05:37 +01:00
|
|
|
import { doFetchUserMemberships } from 'redux/actions/user';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { doFetchChannelListMine } from 'redux/actions/claims';
|
2021-06-18 18:02:36 +02:00
|
|
|
import { doSetActiveChannel } from 'redux/actions/app';
|
2020-06-15 22:33:03 +02:00
|
|
|
import { selectYoutubeChannels } from 'redux/selectors/user';
|
2019-09-26 18:28:08 +02:00
|
|
|
import ChannelsPage from './view';
|
|
|
|
|
2021-08-26 16:51:53 +02:00
|
|
|
const select = (state) => {
|
|
|
|
const channelUrls = selectMyChannelUrls(state);
|
2021-12-02 14:36:53 +01:00
|
|
|
const pendingIds = selectPendingIds(state);
|
|
|
|
|
2021-08-26 16:51:53 +02:00
|
|
|
let pendingChannels = [];
|
2021-12-02 14:36:53 +01:00
|
|
|
if (channelUrls && pendingIds.length > 0) {
|
|
|
|
// TODO: should move this into a memoized selector, as this is a hot area.
|
|
|
|
// For now, I added a check to skip this loop when there are no pending
|
|
|
|
// channels, which is usually the case.
|
2021-08-26 16:51:53 +02:00
|
|
|
channelUrls.map((channelUrl) => {
|
|
|
|
const isPendingUrl = makeSelectClaimIsPending(channelUrl)(state);
|
|
|
|
if (isPendingUrl) pendingChannels.push(channelUrl);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
channelUrls,
|
|
|
|
fetchingChannels: selectFetchingMyChannels(state),
|
|
|
|
youtubeChannels: selectYoutubeChannels(state),
|
|
|
|
pendingChannels,
|
2022-03-09 19:05:37 +01:00
|
|
|
claimsByUri: selectClaimsByUri(state),
|
2021-08-26 16:51:53 +02:00
|
|
|
};
|
|
|
|
};
|
2019-09-26 18:28:08 +02:00
|
|
|
|
2021-06-18 18:02:36 +02:00
|
|
|
const perform = (dispatch) => ({
|
2019-09-26 18:28:08 +02:00
|
|
|
fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
|
2021-06-18 18:02:36 +02:00
|
|
|
doSetActiveChannel: (claimId) => dispatch(doSetActiveChannel(claimId)),
|
2022-03-09 19:05:37 +01:00
|
|
|
doFetchUserMemberships: (claimIds) => dispatch(doFetchUserMemberships(claimIds)),
|
2019-09-26 18:28:08 +02:00
|
|
|
});
|
|
|
|
|
2020-06-15 22:33:03 +02:00
|
|
|
export default connect(select, perform)(ChannelsPage);
|