Page MenuHomePhabricator

D3807.diff
No OneTemporary

D3807.diff

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
@@ -7,14 +7,21 @@
changeThreadSettings,
} from '../actions/thread-actions';
import { createLoadingStatusSelector } from '../selectors/loading-selectors';
+import { threadInfoSelector } from '../selectors/thread-selectors';
+import { threadHasPermission } from '../shared/thread-utils';
import type { LoadingStatus } from '../types/loading-types';
-import { threadTypes, type ThreadInfo } from '../types/thread-types';
+import {
+ threadTypes,
+ type ThreadInfo,
+ threadPermissions,
+} from '../types/thread-types';
import { useServerCall, useDispatchActionPromise } from '../utils/action-utils';
import { useSelector } from '../utils/redux-utils';
type PromoteSidebarType = {
+onPromoteSidebar: () => void,
+loading: LoadingStatus,
+ +canPromoteSidebar: boolean,
};
function usePromoteSidebar(
@@ -28,6 +35,23 @@
);
const loadingStatus = useSelector(loadingStatusSelector);
+ const { parentThreadID } = threadInfo;
+ const parentThreadInfo: ?ThreadInfo = useSelector(state =>
+ parentThreadID ? threadInfoSelector(state)[parentThreadID] : null,
+ );
+ const canChangeThreadType = threadHasPermission(
+ threadInfo,
+ threadPermissions.EDIT_PERMISSIONS,
+ );
+ const canCreateSubchannelsInParent = threadHasPermission(
+ parentThreadInfo,
+ threadPermissions.CREATE_SUBCHANNELS,
+ );
+ const canPromoteSidebar =
+ threadInfo.type === threadTypes.SIDEBAR &&
+ canChangeThreadType &&
+ canCreateSubchannelsInParent;
+
const onClick = React.useCallback(() => {
try {
dispatchActionPromise(
@@ -49,8 +73,9 @@
() => ({
onPromoteSidebar: onClick,
loading: loadingStatus,
+ canPromoteSidebar,
}),
- [onClick, loadingStatus],
+ [onClick, loadingStatus, canPromoteSidebar],
);
return returnValues;
diff --git a/native/chat/settings/thread-settings.react.js b/native/chat/settings/thread-settings.react.js
--- a/native/chat/settings/thread-settings.react.js
+++ b/native/chat/settings/thread-settings.react.js
@@ -11,6 +11,7 @@
removeUsersFromThreadActionTypes,
changeThreadMemberRolesActionTypes,
} from 'lib/actions/thread-actions';
+import { usePromoteSidebar } from 'lib/hooks/promote-sidebar.react';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors';
import {
threadInfoSelector,
@@ -219,6 +220,7 @@
+overlayContext: ?OverlayContextType,
// withKeyboardState
+keyboardState: ?KeyboardState,
+ +canPromoteSidebar: boolean,
};
type State = {
+numMembersShowing: number,
@@ -683,19 +685,7 @@
) => {
const buttons = [];
- const canChangeThreadType = threadHasPermission(
- threadInfo,
- threadPermissions.EDIT_PERMISSIONS,
- );
- const canCreateSubchannelsInParent = threadHasPermission(
- parentThreadInfo,
- threadPermissions.CREATE_SUBCHANNELS,
- );
- const canPromoteSidebar =
- threadInfo.type === threadTypes.SIDEBAR &&
- canChangeThreadType &&
- canCreateSubchannelsInParent;
- if (canPromoteSidebar) {
+ if (this.props.canPromoteSidebar) {
buttons.push({
itemType: 'promoteSidebar',
key: 'promoteSidebar',
@@ -1138,6 +1128,8 @@
const indicatorStyle = useIndicatorStyle();
const overlayContext = React.useContext(OverlayContext);
const keyboardState = React.useContext(KeyboardContext);
+ invariant(threadInfo, 'threadInfo must be defined');
+ const { canPromoteSidebar } = usePromoteSidebar(threadInfo);
return (
<ThreadSettings
{...props}
@@ -1151,6 +1143,7 @@
indicatorStyle={indicatorStyle}
overlayContext={overlayContext}
keyboardState={keyboardState}
+ canPromoteSidebar={canPromoteSidebar}
/>
);
},

File Metadata

Mime Type
text/plain
Expires
Fri, Sep 20, 10:55 PM (8 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2152196
Default Alt Text
D3807.diff (3 KB)

Event Timeline