Move clear function to page switch
This commit is contained in:
parent
aa86815418
commit
5e7fac563f
5 changed files with 27 additions and 44 deletions
|
@ -27,7 +27,6 @@ type Props = {
|
||||||
storeSelection?: boolean,
|
storeSelection?: boolean,
|
||||||
doSetClientSetting: (key: string, value: string, pushPrefs: boolean) => void,
|
doSetClientSetting: (key: string, value: string, pushPrefs: boolean) => void,
|
||||||
isHeaderMenu: boolean,
|
isHeaderMenu: boolean,
|
||||||
hasDefaultChannel: boolean,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ChannelSelector(props: Props) {
|
export default function ChannelSelector(props: Props) {
|
||||||
|
@ -43,13 +42,10 @@ export default function ChannelSelector(props: Props) {
|
||||||
storeSelection,
|
storeSelection,
|
||||||
doSetClientSetting,
|
doSetClientSetting,
|
||||||
isHeaderMenu,
|
isHeaderMenu,
|
||||||
hasDefaultChannel,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const hideAnon = Boolean(props.hideAnon || storeSelection);
|
const hideAnon = Boolean(props.hideAnon || storeSelection);
|
||||||
|
|
||||||
const defaultChannelRef = React.useRef(hasDefaultChannel);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
push,
|
push,
|
||||||
location: { pathname },
|
location: { pathname },
|
||||||
|
@ -66,20 +62,6 @@ 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 (
|
return (
|
||||||
<div className="channel__selector">
|
<div className="channel__selector">
|
||||||
<Menu>
|
<Menu>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { selectClientSetting, selectHomepageData, selectWildWestDisabled } from
|
||||||
import Router from './view';
|
import Router from './view';
|
||||||
import { normalizeURI } from 'util/lbryURI';
|
import { normalizeURI } from 'util/lbryURI';
|
||||||
import { selectTitleForUri } from 'redux/selectors/claims';
|
import { selectTitleForUri } from 'redux/selectors/claims';
|
||||||
import { doSetHasNavigated } from 'redux/actions/app';
|
import { doSetHasNavigated, doSetActiveChannel } from 'redux/actions/app';
|
||||||
import { doUserSetReferrer } from 'redux/actions/user';
|
import { doUserSetReferrer } from 'redux/actions/user';
|
||||||
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
|
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
|
||||||
import { selectUnseenNotificationCount } from 'redux/selectors/notifications';
|
import { selectUnseenNotificationCount } from 'redux/selectors/notifications';
|
||||||
|
@ -39,12 +39,14 @@ const select = (state) => {
|
||||||
wildWestDisabled: selectWildWestDisabled(state),
|
wildWestDisabled: selectWildWestDisabled(state),
|
||||||
unseenCount: selectUnseenNotificationCount(state),
|
unseenCount: selectUnseenNotificationCount(state),
|
||||||
hideTitleNotificationCount: selectClientSetting(state, SETTINGS.HIDE_TITLE_NOTIFICATION_COUNT),
|
hideTitleNotificationCount: selectClientSetting(state, SETTINGS.HIDE_TITLE_NOTIFICATION_COUNT),
|
||||||
|
hasDefaultChannel: Boolean(selectClientSetting(state, SETTINGS.ACTIVE_CHANNEL_CLAIM)),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = {
|
||||||
setHasNavigated: () => dispatch(doSetHasNavigated()),
|
setHasNavigated: doSetHasNavigated,
|
||||||
setReferrer: (referrer) => dispatch(doUserSetReferrer(referrer)),
|
setReferrer: doUserSetReferrer,
|
||||||
});
|
doSetActiveChannel,
|
||||||
|
};
|
||||||
|
|
||||||
export default connect(select, perform)(Router);
|
export default connect(select, perform)(Router);
|
||||||
|
|
|
@ -141,6 +141,8 @@ type Props = {
|
||||||
wildWestDisabled: boolean,
|
wildWestDisabled: boolean,
|
||||||
unseenCount: number,
|
unseenCount: number,
|
||||||
hideTitleNotificationCount: boolean,
|
hideTitleNotificationCount: boolean,
|
||||||
|
hasDefaultChannel: boolean,
|
||||||
|
doSetActiveChannel: (claimId: ?string, override?: boolean) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
type PrivateRouteProps = Props & {
|
type PrivateRouteProps = Props & {
|
||||||
|
@ -182,8 +184,12 @@ function AppRouter(props: Props) {
|
||||||
wildWestDisabled,
|
wildWestDisabled,
|
||||||
unseenCount,
|
unseenCount,
|
||||||
hideTitleNotificationCount,
|
hideTitleNotificationCount,
|
||||||
|
hasDefaultChannel,
|
||||||
|
doSetActiveChannel,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const defaultChannelRef = React.useRef(hasDefaultChannel);
|
||||||
|
|
||||||
const { entries, listen, action: historyAction } = history;
|
const { entries, listen, action: historyAction } = history;
|
||||||
const entryIndex = history.index;
|
const entryIndex = history.index;
|
||||||
const urlParams = new URLSearchParams(search);
|
const urlParams = new URLSearchParams(search);
|
||||||
|
@ -275,6 +281,20 @@ function AppRouter(props: Props) {
|
||||||
}
|
}
|
||||||
}, [currentScroll, pathname, search, hash, resetScroll, hasLinkedCommentInUrl, historyAction]);
|
}, [currentScroll, pathname, search, hash, resetScroll, hasLinkedCommentInUrl, historyAction]);
|
||||||
|
|
||||||
|
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
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
// react-router doesn't decode pathanmes before doing the route matching check
|
// react-router doesn't decode pathanmes before doing the route matching check
|
||||||
// We have to redirect here because if we redirect on the server, it might get encoded again
|
// We have to redirect here because if we redirect on the server, it might get encoded again
|
||||||
// in the browser causing a redirect loop
|
// in the browser causing a redirect loop
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import * as SETTINGS from 'constants/settings';
|
|
||||||
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 { selectActiveChannelClaim } from 'redux/selectors/app';
|
||||||
import { doSetActiveChannel } from 'redux/actions/app';
|
import { doSetActiveChannel } from 'redux/actions/app';
|
||||||
import { selectClientSetting } from 'redux/selectors/settings';
|
|
||||||
|
|
||||||
const select = (state) => ({
|
const select = (state) => ({
|
||||||
myChannelClaims: selectMyChannelClaims(state),
|
myChannelClaims: selectMyChannelClaims(state),
|
||||||
fetchingChannels: selectFetchingMyChannels(state),
|
fetchingChannels: selectFetchingMyChannels(state),
|
||||||
activeChannelClaimId: selectActiveChannelClaim(state)?.claim_id,
|
activeChannelClaimId: selectActiveChannelClaim(state)?.claim_id,
|
||||||
hasDefaultChannel: Boolean(selectClientSetting(state, SETTINGS.ACTIVE_CHANNEL_CLAIM)),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = (dispatch) => ({
|
const perform = (dispatch) => ({
|
||||||
|
|
|
@ -11,7 +11,6 @@ type Props = {
|
||||||
myChannelClaims: ?Array<ChannelClaim>,
|
myChannelClaims: ?Array<ChannelClaim>,
|
||||||
fetchingChannels: boolean,
|
fetchingChannels: boolean,
|
||||||
activeChannelClaimId: ?string,
|
activeChannelClaimId: ?string,
|
||||||
hasDefaultChannel: boolean,
|
|
||||||
setActiveChannel: (claimId: ?string, override?: boolean) => void,
|
setActiveChannel: (claimId: ?string, override?: boolean) => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,12 +23,9 @@ function SelectChannel(props: Props) {
|
||||||
injected = [],
|
injected = [],
|
||||||
tiny,
|
tiny,
|
||||||
activeChannelClaimId,
|
activeChannelClaimId,
|
||||||
hasDefaultChannel,
|
|
||||||
setActiveChannel,
|
setActiveChannel,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const defaultChannelRef = React.useRef(hasDefaultChannel);
|
|
||||||
|
|
||||||
function handleChannelChange(event: SyntheticInputEvent<*>) {
|
function handleChannelChange(event: SyntheticInputEvent<*>) {
|
||||||
const channelClaimId = event.target.value;
|
const channelClaimId = event.target.value;
|
||||||
setActiveChannel(channelClaimId);
|
setActiveChannel(channelClaimId);
|
||||||
|
@ -40,20 +36,6 @@ function SelectChannel(props: Props) {
|
||||||
mine = myChannelClaims.filter((x) => channelIds.includes(x.claim_id));
|
mine = myChannelClaims.filter((x) => channelIds.includes(x.claim_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
defaultChannelRef.current = hasDefaultChannel;
|
|
||||||
}, [hasDefaultChannel]);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
// has a default channel selected, clear the current active channel
|
|
||||||
if (defaultChannelRef.current) {
|
|
||||||
setActiveChannel(null, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormField
|
<FormField
|
||||||
|
|
Loading…
Add table
Reference in a new issue