Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3400494
D3807.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3807.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 3, 7:27 AM (24 m, 17 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2610861
Default Alt Text
D3807.diff (3 KB)
Attached To
Mode
D3807: [lib, native] [move] [ENG-991] replace canPromote thread logic to lib hook
Attached
Detach File
Event Timeline
Log In to Comment