diff --git a/ui/component/channelSelector/index.js b/ui/component/channelSelector/index.js
index 50d3d014f..0de8f395c 100644
--- a/ui/component/channelSelector/index.js
+++ b/ui/component/channelSelector/index.js
@@ -1,9 +1,11 @@
import { connect } from 'react-redux';
+import * as SETTINGS from 'constants/settings';
import { selectMyChannelClaims, selectClaimsByUri, selectOdyseeMembershipForUri } from 'redux/selectors/claims';
import { selectActiveChannelClaim, selectIncognito } from 'redux/selectors/app';
import { doSetActiveChannel, doSetIncognito } from 'redux/actions/app';
import { doFetchUserMemberships } from 'redux/actions/user';
import { doSetClientSetting } from 'redux/actions/settings';
+import { selectClientSetting } from 'redux/selectors/settings';
import ChannelSelector from './view';
const select = (state, props) => {
@@ -15,6 +17,7 @@ const select = (state, props) => {
incognito: selectIncognito(state),
odyseeMembershipByUri: (uri) => selectOdyseeMembershipForUri(state, uri),
claimsByUri: selectClaimsByUri(state),
+ hasDefaultChannel: Boolean(selectClientSetting(state, SETTINGS.ACTIVE_CHANNEL_CLAIM)),
};
};
diff --git a/ui/component/channelSelector/view.jsx b/ui/component/channelSelector/view.jsx
index ea3a156a9..de3569c1b 100644
--- a/ui/component/channelSelector/view.jsx
+++ b/ui/component/channelSelector/view.jsx
@@ -18,7 +18,7 @@ type Props = {
onChannelSelect: (url: string) => void,
hideAnon?: boolean,
activeChannelClaim: ?ChannelClaim,
- doSetActiveChannel: (string) => void,
+ doSetActiveChannel: (claimId: ?string, override?: boolean) => void,
incognito: boolean,
doSetIncognito: (boolean) => void,
claimsByUri: { [string]: any },
@@ -27,6 +27,7 @@ type Props = {
storeSelection?: boolean,
doSetClientSetting: (key: string, value: string, pushPrefs: boolean) => void,
isHeaderMenu: boolean,
+ hasDefaultChannel: boolean,
};
export default function ChannelSelector(props: Props) {
@@ -34,7 +35,6 @@ export default function ChannelSelector(props: Props) {
channels,
activeChannelClaim,
doSetActiveChannel,
- hideAnon = false,
incognito,
doSetIncognito,
odyseeMembershipByUri,
@@ -43,8 +43,13 @@ export default function ChannelSelector(props: Props) {
storeSelection,
doSetClientSetting,
isHeaderMenu,
+ hasDefaultChannel,
} = props;
+ const hideAnon = Boolean(props.hideAnon || storeSelection);
+
+ const defaultChannelRef = React.useRef(hasDefaultChannel);
+
const {
push,
location: { pathname },
@@ -61,6 +66,20 @@ export default function ChannelSelector(props: Props) {
}
}
+ React.useEffect(() => {
+ defaultChannelRef.current = hasDefaultChannel;
+ }, [hasDefaultChannel]);
+
+ React.useEffect(() => {
+ return () => {
+ // has a default channel selected, clear the current active channel
+ if (defaultChannelRef.current) {
+ doSetActiveChannel(null, true);
+ }
+ };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
+
return (