More sidebar optimizations

- Remove the odd resolve call that's lingering in `App`. Feels out of place, plus we don't need it now since the "active subs" claim search would contain resolved results.

- Don't search for active subs if Following count is zero.
This commit is contained in:
infinite-persistence 2022-03-22 15:35:45 +08:00 committed by Thomas Zarebczan
parent 56966ffa31
commit 429653a7dc
4 changed files with 14 additions and 23 deletions

View file

@ -10,9 +10,8 @@ import {
selectHomepageFetched,
} from 'redux/selectors/user';
import { selectUnclaimedRewards } from 'redux/selectors/rewards';
import { doFetchChannelListMine, doFetchCollectionListMine, doResolveUris } from 'redux/actions/claims';
import { doFetchChannelListMine, doFetchCollectionListMine } from 'redux/actions/claims';
import { selectMyChannelClaimIds } from 'redux/selectors/claims';
import { selectSubscriptions } from 'redux/selectors/subscriptions';
import { selectLanguage, selectLoadedLanguages, selectThemePath } from 'redux/selectors/settings';
import {
selectIsUpgradeAvailable,
@ -46,7 +45,6 @@ const select = (state) => ({
syncFatalError: selectSyncFatalError(state),
activeChannelClaim: selectActiveChannelClaim(state),
myChannelClaimIds: selectMyChannelClaimIds(state),
subscriptions: selectSubscriptions(state),
hasPremiumPlus: selectOdyseeMembershipIsPremiumPlus(state),
homepageFetched: selectHomepageFetched(state),
});
@ -62,7 +60,6 @@ const perform = (dispatch) => ({
setActiveChannelIfNotSet: () => dispatch(doSetActiveChannel()),
setIncognito: () => dispatch(doSetIncognito()),
fetchModBlockedList: () => dispatch(doFetchModBlockedList()),
resolveUris: (uris) => dispatch(doResolveUris(uris)),
fetchModAmIList: () => dispatch(doFetchCommentModAmIList()),
});

View file

@ -1,6 +1,6 @@
// @flow
import * as PAGES from 'constants/pages';
import React, { useEffect, useRef, useState, useLayoutEffect } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { lazyImport } from 'util/lazyImport';
import { tusUnlockAndNotify, tusHandleTabUpdates } from 'util/tus';
import classnames from 'classnames';
@ -24,7 +24,6 @@ import usePersistedState from 'effects/use-persisted-state';
import useConnectionStatus from 'effects/use-connection-status';
import Spinner from 'component/spinner';
import LANGUAGES from 'constants/languages';
import { SIDEBAR_SUBS_DISPLAYED } from 'constants/subscriptions';
import YoutubeWelcome from 'web/component/youtubeReferralWelcome';
import {
useDegradedPerformance,
@ -86,12 +85,10 @@ type Props = {
syncFatalError: boolean,
activeChannelClaim: ?ChannelClaim,
myChannelClaimIds: ?Array<string>,
subscriptions: Array<Subscription>,
hasPremiumPlus: ?boolean,
setActiveChannelIfNotSet: () => void,
setIncognito: (boolean) => void,
fetchModBlockedList: () => void,
resolveUris: (Array<string>) => void,
fetchModAmIList: () => void,
homepageFetched: boolean,
};
@ -126,8 +123,6 @@ function App(props: Props) {
setActiveChannelIfNotSet,
setIncognito,
fetchModBlockedList,
resolveUris,
subscriptions,
hasPremiumPlus,
fetchModAmIList,
homepageFetched,
@ -149,10 +144,8 @@ function App(props: Props) {
const { pathname, hash, search } = props.location;
const [upgradeNagClosed, setUpgradeNagClosed] = useState(false);
const [resolvedSubscriptions, setResolvedSubscriptions] = useState(false);
const [retryingSync, setRetryingSync] = useState(false);
const [langRenderKey, setLangRenderKey] = useState(0);
const [sidebarOpen] = usePersistedState('sidebar', true);
const [seenSunsestMessage, setSeenSunsetMessage] = usePersistedState('lbrytv-sunset', false);
const showUpgradeButton =
(autoUpdateDownloaded || (process.platform === 'linux' && isUpgradeAvailable)) && !upgradeNagClosed;
@ -169,7 +162,6 @@ function App(props: Props) {
const hasNoChannels = myChannelClaimIds && myChannelClaimIds.length === 0;
const shouldMigrateLanguage = LANGUAGE_MIGRATIONS[language];
const hasActiveChannelClaim = activeChannelClaim !== undefined;
const isPersonalized = !IS_WEB || hasVerifiedEmail;
const renderFiledrop = !isMobile && isAuthenticated;
const connectionStatus = useConnectionStatus();
@ -475,16 +467,6 @@ function App(props: Props) {
}
}, [hasVerifiedEmail, signIn, hasSignedIn]);
// batch resolve subscriptions to be used by the sideNavigation component.
// add it here so that it only resolves the first time, despite route changes.
// useLayoutEffect because it has to be executed before the sideNavigation component requests them
useLayoutEffect(() => {
if (sidebarOpen && isPersonalized && subscriptions && !resolvedSubscriptions) {
setResolvedSubscriptions(true);
resolveUris(subscriptions.slice(0, SIDEBAR_SUBS_DISPLAYED).map((sub) => sub.uri));
}
}, [sidebarOpen, isPersonalized, resolvedSubscriptions, subscriptions, resolveUris, setResolvedSubscriptions]);
useDegradedPerformance(setLbryTvApiStatus, user);
useAdOutbrain(Boolean(hasPremiumPlus), isAuthenticated);

View file

@ -336,6 +336,10 @@ function SideNavigation(props: Props) {
lastActiveSubs && lastActiveSubs.length > 0 ? lastActiveSubs : subscriptions.slice(0, SIDEBAR_SUBS_DISPLAYED);
}
if (lastActiveSubs === undefined) {
return null; // Don't show yet, just wait to save some renders
}
return (
<ul className="navigation__secondary navigation-links">
{subscriptions.length > SIDEBAR_SUBS_DISPLAYED && (

View file

@ -118,6 +118,14 @@ export function doFetchLastActiveSubs(forceFetch: boolean = false, count: number
const channelIds = subscriptions.map((sub) => parseIdFromUri(sub.uri));
activeSubsLastFetchedTime = now;
if (channelIds.length === 0) {
dispatch({
type: ACTIONS.FETCH_LAST_ACTIVE_SUBS_DONE,
data: [],
});
return;
}
const searchOptions = {
limit_claims_per_channel: 1,
channel_ids: channelIds,