From 19f22b982fa554159930f61604f60ace68aa8d1b Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Sat, 7 Oct 2023 01:38:31 +0800 Subject: [PATCH] Sidebar: do not show deleted channels --- ui/component/sideNavigation/index.js | 13 ++++++++++++- ui/component/sideNavigation/view.jsx | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/component/sideNavigation/index.js b/ui/component/sideNavigation/index.js index c283482d7f..232697705a 100644 --- a/ui/component/sideNavigation/index.js +++ b/ui/component/sideNavigation/index.js @@ -18,7 +18,7 @@ import { selectUserVerifiedEmail, selectUser } from 'redux/selectors/user'; import { selectClientSettings, selectHomepageData } from 'redux/selectors/settings'; import { doOpenModal, doSignOut } from 'redux/actions/app'; import { selectUnseenNotificationCount } from 'redux/selectors/notifications'; -import { selectClaimsByUri, selectPurchaseUriSuccess } from 'redux/selectors/claims'; +import { selectClaimsByUri, selectPurchaseUriSuccess, selectResolvingUris } from 'redux/selectors/claims'; import { selectUserHasValidOdyseeMembership } from 'redux/selectors/memberships'; import { GetLinksData } from 'util/buildHomepage'; @@ -60,6 +60,8 @@ const selectSidebarCategories = createSelector( function doGetDisplayedSubs(filter) { return async (dispatch, getState) => { + await waitIfResolving(1000, 5, getState); + const state = getState(); const claimsByUri = selectClaimsByUri(state); const subs = selectSubscriptions(state); @@ -79,6 +81,7 @@ function doGetDisplayedSubs(filter) { }); } else { filteredSubs = lastActiveSubs?.length > 0 ? lastActiveSubs : subs.slice(0, SIDEBAR_SUBS_DISPLAYED); + filteredSubs = filteredSubs.filter((sub) => claimsByUri[sub?.uri]); } } @@ -86,6 +89,14 @@ function doGetDisplayedSubs(filter) { }; } +async function waitIfResolving(waitMs, maxAttempts, getState) { + let isResolvingUris = selectResolvingUris(getState()).length > 0; + for (let waitCount = 0; isResolvingUris && waitCount < maxAttempts; ++waitCount) { + await new Promise((resolve) => setTimeout(resolve, waitMs)); + isResolvingUris = selectResolvingUris(getState()).length > 0; + } +} + // **************************************************************************** // SideNavigation // **************************************************************************** diff --git a/ui/component/sideNavigation/view.jsx b/ui/component/sideNavigation/view.jsx index d0a9e7f403..3877c6be8c 100644 --- a/ui/component/sideNavigation/view.jsx +++ b/ui/component/sideNavigation/view.jsx @@ -549,6 +549,7 @@ function SideNavigation(props: Props) { React.useEffect(() => { if (showSubsSection) { + // Done this way to avoid over-render from claimsByUris[]. doGetDisplayedSubs(subscriptionFilter).then((result) => setDisplayedSubs(result)); } }, [subscriptionFilter, showSubsSection, doGetDisplayedSubs]);