Set 'activeChannel' before entering Dashboard

## Issue
6237: Analytics button from Channels page doesn't open analytics to right channel
This commit is contained in:
infinite-persistence 2021-06-19 00:02:36 +08:00 committed by Thomas Zarebczan
parent 16cfe1c815
commit f4d327f1f4
2 changed files with 12 additions and 4 deletions

View file

@ -5,18 +5,20 @@ import {
doFetchChannelListMine, doFetchChannelListMine,
selectFetchingMyChannels, selectFetchingMyChannels,
} from 'lbry-redux'; } from 'lbry-redux';
import { doSetActiveChannel } from 'redux/actions/app';
import { selectYoutubeChannels } from 'redux/selectors/user'; import { selectYoutubeChannels } from 'redux/selectors/user';
import ChannelsPage from './view'; import ChannelsPage from './view';
const select = state => ({ const select = (state) => ({
channelUrls: selectMyChannelUrls(state), channelUrls: selectMyChannelUrls(state),
channels: selectMyChannelClaims(state), channels: selectMyChannelClaims(state),
fetchingChannels: selectFetchingMyChannels(state), fetchingChannels: selectFetchingMyChannels(state),
youtubeChannels: selectYoutubeChannels(state), youtubeChannels: selectYoutubeChannels(state),
}); });
const perform = dispatch => ({ const perform = (dispatch) => ({
fetchChannelListMine: () => dispatch(doFetchChannelListMine()), fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
doSetActiveChannel: (claimId) => dispatch(doSetActiveChannel(claimId)),
}); });
export default connect(select, perform)(ChannelsPage); export default connect(select, perform)(ChannelsPage);

View file

@ -11,6 +11,7 @@ import Yrbl from 'component/yrbl';
import LbcSymbol from 'component/common/lbc-symbol'; import LbcSymbol from 'component/common/lbc-symbol';
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
import HelpLink from 'component/common/help-link'; import HelpLink from 'component/common/help-link';
import { useHistory } from 'react-router';
type Props = { type Props = {
channels: Array<ChannelClaim>, channels: Array<ChannelClaim>,
@ -18,13 +19,15 @@ type Props = {
fetchChannelListMine: () => void, fetchChannelListMine: () => void,
fetchingChannels: boolean, fetchingChannels: boolean,
youtubeChannels: ?Array<any>, youtubeChannels: ?Array<any>,
doSetActiveChannel: (string) => void,
}; };
export default function ChannelsPage(props: Props) { export default function ChannelsPage(props: Props) {
const { channels, channelUrls, fetchChannelListMine, fetchingChannels, youtubeChannels } = props; const { channels, channelUrls, fetchChannelListMine, fetchingChannels, youtubeChannels, doSetActiveChannel } = props;
const [rewardData, setRewardData] = React.useState(); const [rewardData, setRewardData] = React.useState();
const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length); const hasYoutubeChannels = youtubeChannels && Boolean(youtubeChannels.length);
const hasPendingChannels = channels && channels.some((channel) => channel.confirmations < 0); const hasPendingChannels = channels && channels.some((channel) => channel.confirmations < 0);
const { push } = useHistory();
useEffect(() => { useEffect(() => {
fetchChannelListMine(); fetchChannelListMine();
@ -62,7 +65,10 @@ export default function ChannelsPage(props: Props) {
button="alt" button="alt"
icon={ICONS.ANALYTICS} icon={ICONS.ANALYTICS}
label={__('Analytics')} label={__('Analytics')}
navigate={`/$/${PAGES.CREATOR_DASHBOARD}?channel=${encodeURIComponent(claim.canonical_url)}`} onClick={() => {
doSetActiveChannel(claim.claim_id);
push(`/$/${PAGES.CREATOR_DASHBOARD}`);
}}
/> />
</div> </div>
); );