diff --git a/lib/hooks/promote-sidebar.react.js b/lib/hooks/promote-sidebar.react.js --- a/lib/hooks/promote-sidebar.react.js +++ b/lib/hooks/promote-sidebar.react.js @@ -9,8 +9,8 @@ import { createLoadingStatusSelector } from '../selectors/loading-selectors.js'; import { threadInfoSelector } from '../selectors/thread-selectors.js'; import { - threadHasPermission, threadIsSidebar, + useThreadHasPermission, } from '../shared/thread-utils.js'; import type { LoadingStatus } from '../types/loading-types.js'; import type { ThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; @@ -19,23 +19,24 @@ import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector } from '../utils/redux-utils.js'; -function canPromoteSidebar( +function useCanPromoteSidebar( sidebarThreadInfo: ThreadInfo, parentThreadInfo: ?ThreadInfo, ): boolean { - if (!threadIsSidebar(sidebarThreadInfo)) { - return false; - } - - const canChangeThreadType = threadHasPermission( + const canChangeThreadType = useThreadHasPermission( sidebarThreadInfo, threadPermissions.EDIT_PERMISSIONS, ); - const canCreateSubchannelsInParent = threadHasPermission( + const canCreateSubchannelsInParent = useThreadHasPermission( parentThreadInfo, threadPermissions.CREATE_SUBCHANNELS, ); - return canChangeThreadType && canCreateSubchannelsInParent; + + return ( + threadIsSidebar(sidebarThreadInfo) && + canChangeThreadType && + canCreateSubchannelsInParent + ); } type PromoteSidebarType = { @@ -60,7 +61,7 @@ parentThreadID ? threadInfoSelector(state)[parentThreadID] : null, ); - const canPromote = canPromoteSidebar(threadInfo, parentThreadInfo); + const canPromote = useCanPromoteSidebar(threadInfo, parentThreadInfo); const onClick = React.useCallback(() => { try { @@ -91,4 +92,4 @@ return returnValues; } -export { usePromoteSidebar, canPromoteSidebar }; +export { usePromoteSidebar, useCanPromoteSidebar }; diff --git a/web/modals/threads/notifications/notifications-modal.react.js b/web/modals/threads/notifications/notifications-modal.react.js --- a/web/modals/threads/notifications/notifications-modal.react.js +++ b/web/modals/threads/notifications/notifications-modal.react.js @@ -6,7 +6,7 @@ useUpdateSubscription, updateSubscriptionActionTypes, } from 'lib/actions/user-actions.js'; -import { canPromoteSidebar } from 'lib/hooks/promote-sidebar.react.js'; +import { useCanPromoteSidebar } from 'lib/hooks/promote-sidebar.react.js'; import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { threadIsSidebar } from 'lib/shared/thread-utils.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; @@ -192,6 +192,7 @@ ? 'Thread notifications' : 'Channel notifications'; + const canPromoteSidebar = useCanPromoteSidebar(threadInfo, parentThreadInfo); const noticeText = React.useMemo(() => { if (!isSidebar) { return null; @@ -207,7 +208,7 @@ 'must also be there.'}

- {canPromoteSidebar(threadInfo, parentThreadInfo) + {canPromoteSidebar ? 'If you want to move this thread to Background, ' + 'you can either move the parent to Background, ' + 'or you can promote the thread to a channel.' @@ -216,7 +217,7 @@

); - }, [isSidebar, parentThreadInfo, threadInfo]); + }, [isSidebar, canPromoteSidebar]); const parentThreadIsInBackground = isSidebar && !parentThreadInfo?.currentUser.subscription.home; @@ -233,7 +234,7 @@ 'thread must also be there.'}

- {canPromoteSidebar(threadInfo, parentThreadInfo) + {canPromoteSidebar ? 'If you want to change the notif settings for this thread, ' + 'you can either change the notif settings for the parent, ' + 'or you can promote the thread to a channel.' @@ -259,9 +260,8 @@ focusedBadgeOnlyItem, focusedItem, noticeText, - parentThreadInfo, parentThreadIsInBackground, - threadInfo, + canPromoteSidebar, ]); const saveButton = React.useMemo(() => {