Fix default channel changing with active channel on header
This commit is contained in:
parent
9325a3e03e
commit
f191cf0b88
6 changed files with 29 additions and 19 deletions
|
@ -1,23 +1,23 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import * as SETTINGS from 'constants/settings';
|
|
||||||
import { selectMyChannelClaims, selectClaimsByUri, selectOdyseeMembershipForUri } from 'redux/selectors/claims';
|
import { selectMyChannelClaims, selectClaimsByUri, selectOdyseeMembershipForUri } from 'redux/selectors/claims';
|
||||||
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
|
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
|
||||||
import { doSetActiveChannel, doSetIncognito } from 'redux/actions/app';
|
import { doSetActiveChannel, doSetIncognito } from 'redux/actions/app';
|
||||||
import { doFetchUserMemberships } from 'redux/actions/user';
|
import { doFetchUserMemberships } from 'redux/actions/user';
|
||||||
import { doSetClientSetting } from 'redux/actions/settings';
|
import { doSetClientSetting } from 'redux/actions/settings';
|
||||||
import { selectClientSetting } from 'redux/selectors/settings';
|
import { selectDefaultChannelClaim } from 'redux/selectors/settings';
|
||||||
import ChannelSelector from './view';
|
import ChannelSelector from './view';
|
||||||
|
|
||||||
const select = (state, props) => {
|
const select = (state, props) => {
|
||||||
|
const { storeSelection } = props;
|
||||||
const activeChannelClaim = selectActiveChannelClaim(state);
|
const activeChannelClaim = selectActiveChannelClaim(state);
|
||||||
|
const defaultChannelClaim = selectDefaultChannelClaim(state);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
channels: selectMyChannelClaims(state),
|
channels: selectMyChannelClaims(state),
|
||||||
activeChannelClaim,
|
activeChannelClaim: storeSelection ? defaultChannelClaim : activeChannelClaim,
|
||||||
incognito: selectIncognito(state),
|
incognito: selectIncognito(state),
|
||||||
odyseeMembershipByUri: (uri) => selectOdyseeMembershipForUri(state, uri),
|
odyseeMembershipByUri: (uri) => selectOdyseeMembershipForUri(state, uri),
|
||||||
claimsByUri: selectClaimsByUri(state),
|
claimsByUri: selectClaimsByUri(state),
|
||||||
hasDefaultChannel: Boolean(selectClientSetting(state, SETTINGS.ACTIVE_CHANNEL_CLAIM)),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doSignOut } from 'redux/actions/app';
|
import { doSignOut } from 'redux/actions/app';
|
||||||
import { selectActiveChannelClaim } from 'redux/selectors/app';
|
import { selectDefaultChannelClaim } from 'redux/selectors/settings';
|
||||||
import { selectMyChannelClaimIds } from 'redux/selectors/claims';
|
import { selectMyChannelClaimIds } from 'redux/selectors/claims';
|
||||||
import { selectUserEmail, selectUserVerifiedEmail } from 'redux/selectors/user';
|
import { selectUserEmail, selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||||
import HeaderProfileMenuButton from './view';
|
import HeaderProfileMenuButton from './view';
|
||||||
|
|
||||||
const select = (state) => ({
|
const select = (state) => ({
|
||||||
myChannelClaimIds: selectMyChannelClaimIds(state),
|
myChannelClaimIds: selectMyChannelClaimIds(state),
|
||||||
activeChannelClaim: selectActiveChannelClaim(state),
|
defaultChannelClaim: selectDefaultChannelClaim(state),
|
||||||
authenticated: selectUserVerifiedEmail(state),
|
authenticated: selectUserVerifiedEmail(state),
|
||||||
email: selectUserEmail(state),
|
email: selectUserEmail(state),
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,21 +18,21 @@ import Button from 'component/button';
|
||||||
|
|
||||||
type HeaderMenuButtonProps = {
|
type HeaderMenuButtonProps = {
|
||||||
myChannelClaimIds: ?Array<string>,
|
myChannelClaimIds: ?Array<string>,
|
||||||
activeChannelClaim: ?ChannelClaim,
|
defaultChannelClaim: ?ChannelClaim,
|
||||||
authenticated: boolean,
|
authenticated: boolean,
|
||||||
email: ?string,
|
email: ?string,
|
||||||
signOut: () => void,
|
signOut: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function HeaderProfileMenuButton(props: HeaderMenuButtonProps) {
|
export default function HeaderProfileMenuButton(props: HeaderMenuButtonProps) {
|
||||||
const { myChannelClaimIds, activeChannelClaim, authenticated, email, signOut } = props;
|
const { myChannelClaimIds, defaultChannelClaim, authenticated, email, signOut } = props;
|
||||||
|
|
||||||
const [anchorEl, setAnchorEl] = React.useState(null);
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
||||||
const open = Boolean(anchorEl);
|
const open = Boolean(anchorEl);
|
||||||
const handleClick = (event) => setAnchorEl(!anchorEl ? event.currentTarget : null);
|
const handleClick = (event) => setAnchorEl(!anchorEl ? event.currentTarget : null);
|
||||||
const handleClose = () => setAnchorEl(null);
|
const handleClose = () => setAnchorEl(null);
|
||||||
|
|
||||||
const activeChannelUrl = activeChannelClaim && activeChannelClaim.permanent_url;
|
const activeChannelUrl = defaultChannelClaim && defaultChannelClaim.permanent_url;
|
||||||
// activeChannel will be: undefined = fetching, null = nothing, or { channel claim }
|
// activeChannel will be: undefined = fetching, null = nothing, or { channel claim }
|
||||||
const noActiveChannel = activeChannelUrl === null;
|
const noActiveChannel = activeChannelUrl === null;
|
||||||
const pendingChannelFetch = !noActiveChannel && myChannelClaimIds === undefined;
|
const pendingChannelFetch = !noActiveChannel && myChannelClaimIds === undefined;
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import SelectChannel from './view';
|
import SelectChannel from './view';
|
||||||
import { selectMyChannelClaims, selectFetchingMyChannels } from 'redux/selectors/claims';
|
import { selectMyChannelClaims, selectFetchingMyChannels } from 'redux/selectors/claims';
|
||||||
import { selectActiveChannelClaim } from 'redux/selectors/app';
|
import { selectActiveChannelClaimId } from 'redux/selectors/app';
|
||||||
import { doSetActiveChannel } from 'redux/actions/app';
|
import { doSetActiveChannel } from 'redux/actions/app';
|
||||||
|
|
||||||
const select = (state) => ({
|
const select = (state) => ({
|
||||||
myChannelClaims: selectMyChannelClaims(state),
|
myChannelClaims: selectMyChannelClaims(state),
|
||||||
fetchingChannels: selectFetchingMyChannels(state),
|
fetchingChannels: selectFetchingMyChannels(state),
|
||||||
activeChannelClaimId: selectActiveChannelClaim(state)?.claim_id,
|
activeChannelClaimId: selectActiveChannelClaimId(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = {
|
||||||
setActiveChannel: (claimId, override) => dispatch(doSetActiveChannel(claimId, override)),
|
setActiveChannel: doSetActiveChannel,
|
||||||
});
|
};
|
||||||
|
|
||||||
export default connect(select, perform)(SelectChannel);
|
export default connect(select, perform)(SelectChannel);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import * as SETTINGS from 'constants/settings';
|
|
||||||
import { selectClaimWithId, selectMyChannelClaims, selectStakedLevelForChannelUri } from 'redux/selectors/claims';
|
import { selectClaimWithId, selectMyChannelClaims, selectStakedLevelForChannelUri } from 'redux/selectors/claims';
|
||||||
import { selectUserEmail } from 'redux/selectors/user';
|
import { selectUserEmail } from 'redux/selectors/user';
|
||||||
import { selectClientSetting } from 'redux/selectors/settings';
|
import { selectDefaultChannelClaim } from 'redux/selectors/settings';
|
||||||
|
|
||||||
export const selectState = (state) => state.app || {};
|
export const selectState = (state) => state.app || {};
|
||||||
|
|
||||||
|
@ -70,9 +69,9 @@ export const selectActiveChannelId = (state) => selectState(state).activeChannel
|
||||||
export const selectActiveChannelClaim = createSelector(
|
export const selectActiveChannelClaim = createSelector(
|
||||||
(state) => selectClaimWithId(state, selectActiveChannelId(state)), // i.e. 'byId[activeChannelId]' specifically, instead of just 'byId'.
|
(state) => selectClaimWithId(state, selectActiveChannelId(state)), // i.e. 'byId[activeChannelId]' specifically, instead of just 'byId'.
|
||||||
(state) => selectUserEmail(state),
|
(state) => selectUserEmail(state),
|
||||||
(state) => selectClaimWithId(state, selectClientSetting(state, SETTINGS.ACTIVE_CHANNEL_CLAIM)),
|
selectDefaultChannelClaim,
|
||||||
selectMyChannelClaims,
|
selectMyChannelClaims,
|
||||||
(activeChannelClaim, userEmail, storedChannel, myChannelClaims) => {
|
(activeChannelClaim, userEmail, defaultChannel, myChannelClaims) => {
|
||||||
// Null: has none. Undefined: not resolved, default state, could have or not
|
// Null: has none. Undefined: not resolved, default state, could have or not
|
||||||
if (!userEmail || myChannelClaims === null) {
|
if (!userEmail || myChannelClaims === null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -82,7 +81,7 @@ export const selectActiveChannelClaim = createSelector(
|
||||||
|
|
||||||
if (activeChannelClaim) return activeChannelClaim;
|
if (activeChannelClaim) return activeChannelClaim;
|
||||||
|
|
||||||
if (storedChannel) return storedChannel;
|
if (defaultChannel) return defaultChannel;
|
||||||
|
|
||||||
const myChannelClaimsByEffectiveAmount = myChannelClaims.slice().sort((a, b) => {
|
const myChannelClaimsByEffectiveAmount = myChannelClaims.slice().sort((a, b) => {
|
||||||
const effectiveAmountA = (a.meta && Number(a.meta.effective_amount)) || 0;
|
const effectiveAmountA = (a.meta && Number(a.meta.effective_amount)) || 0;
|
||||||
|
@ -100,6 +99,11 @@ export const selectActiveChannelClaim = createSelector(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectActiveChannelClaimId = createSelector(
|
||||||
|
selectActiveChannelClaim,
|
||||||
|
(activeChannelClaim) => activeChannelClaim?.claim_id
|
||||||
|
);
|
||||||
|
|
||||||
export const selectActiveChannelStakedLevel = (state) => {
|
export const selectActiveChannelStakedLevel = (state) => {
|
||||||
const activeChannelClaim = selectActiveChannelClaim(state);
|
const activeChannelClaim = selectActiveChannelClaim(state);
|
||||||
if (!activeChannelClaim) {
|
if (!activeChannelClaim) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import SUPPORTED_BROWSER_LANGUAGES from 'constants/supported_browser_languages';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { ENABLE_MATURE } from 'config';
|
import { ENABLE_MATURE } from 'config';
|
||||||
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
|
import { getDefaultHomepageKey, getDefaultLanguage } from 'util/default-languages';
|
||||||
|
import { selectClaimWithId } from 'redux/selectors/claims';
|
||||||
|
|
||||||
const selectState = (state) => state.settings || {};
|
const selectState = (state) => state.settings || {};
|
||||||
|
|
||||||
|
@ -81,3 +82,8 @@ export const selectWildWestDisabled = (state) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selectosNotificationsEnabled = (state) => selectClientSetting(state, SETTINGS.OS_NOTIFICATIONS_ENABLED);
|
export const selectosNotificationsEnabled = (state) => selectClientSetting(state, SETTINGS.OS_NOTIFICATIONS_ENABLED);
|
||||||
|
|
||||||
|
export const selectDefaultChannelClaim = createSelector(
|
||||||
|
(state) => selectClaimWithId(state, selectClientSetting(state, SETTINGS.ACTIVE_CHANNEL_CLAIM)),
|
||||||
|
(defaultChannelClaim) => defaultChannelClaim
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in a new issue