diff --git a/web/chat/thread-menu.react.js b/web/chat/thread-menu.react.js
index e1848a259..17213f1b2 100644
--- a/web/chat/thread-menu.react.js
+++ b/web/chat/thread-menu.react.js
@@ -1,314 +1,314 @@
// @flow
import * as React from 'react';
import {
leaveThreadActionTypes,
useLeaveThread,
} from 'lib/actions/thread-actions.js';
import { useModalContext } from 'lib/components/modal-provider.react.js';
import SWMansionIcon from 'lib/components/swmansion-icon.react.js';
import { usePromoteSidebar } from 'lib/hooks/promote-sidebar.react.js';
import { childThreadInfos } from 'lib/selectors/thread-selectors.js';
import {
- threadHasPermission,
threadIsChannel,
+ useThreadHasPermission,
viewerIsMember,
} from 'lib/shared/thread-utils.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import { threadPermissions } from 'lib/types/thread-permission-types.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js';
import css from './thread-menu.css';
import MenuItem from '../components/menu-item.react.js';
import Menu from '../components/menu.react.js';
import SidebarPromoteModal from '../modals/chat/sidebar-promote-modal.react.js';
import ConfirmLeaveThreadModal from '../modals/threads/confirm-leave-thread-modal.react.js';
import ComposeSubchannelModal from '../modals/threads/create/compose-subchannel-modal.react.js';
import ThreadSettingsMediaGalleryModal from '../modals/threads/gallery/thread-settings-media-gallery.react.js';
import ThreadMembersModal from '../modals/threads/members/members-modal.react.js';
import ThreadNotificationsModal from '../modals/threads/notifications/notifications-modal.react.js';
import ThreadSettingsModal from '../modals/threads/settings/thread-settings-modal.react.js';
import SidebarsModal from '../modals/threads/sidebars/sidebars-modal.react.js';
import SubchannelsModal from '../modals/threads/subchannels/subchannels-modal.react.js';
import { useSelector } from '../redux/redux-utils.js';
type ThreadMenuProps = {
+threadInfo: ThreadInfo,
};
function ThreadMenu(props: ThreadMenuProps): React.Node {
const { pushModal, popModal } = useModalContext();
const { threadInfo } = props;
const { onPromoteSidebar, canPromoteSidebar } = usePromoteSidebar(threadInfo);
const onClickSettings = React.useCallback(
() => pushModal(),
[pushModal, threadInfo.id],
);
const settingsItem = React.useMemo(() => {
return (
);
}, [onClickSettings]);
const onClickMembers = React.useCallback(
() =>
pushModal(
,
),
[popModal, pushModal, threadInfo.id],
);
const membersItem = React.useMemo(() => {
if (threadInfo.type === threadTypes.PERSONAL) {
return null;
}
return (
);
}, [onClickMembers, threadInfo.type]);
const onClickThreadMediaGallery = React.useCallback(
() =>
pushModal(
,
),
[popModal, pushModal, threadInfo],
);
const threadMediaGalleryItem = React.useMemo(
() => (
),
[onClickThreadMediaGallery],
);
const childThreads = useSelector(
state => childThreadInfos(state)[threadInfo.id],
);
const hasSidebars = React.useMemo(() => {
return childThreads?.some(
childThreadInfo => childThreadInfo.type === threadTypes.SIDEBAR,
);
}, [childThreads]);
const onClickSidebars = React.useCallback(
() =>
pushModal(),
[popModal, pushModal, threadInfo.id],
);
const sidebarItem = React.useMemo(() => {
if (!hasSidebars) {
return null;
}
return (
);
}, [hasSidebars, onClickSidebars]);
- const canCreateSubchannels = React.useMemo(
- () => threadHasPermission(threadInfo, threadPermissions.CREATE_SUBCHANNELS),
- [threadInfo],
+ const canCreateSubchannels = useThreadHasPermission(
+ threadInfo,
+ threadPermissions.CREATE_SUBCHANNELS,
);
const hasSubchannels = React.useMemo(() => {
return !!childThreads?.some(threadIsChannel);
}, [childThreads]);
const onClickViewSubchannels = React.useCallback(
() =>
pushModal(
,
),
[popModal, pushModal, threadInfo.id],
);
const viewSubchannelsItem = React.useMemo(() => {
if (!hasSubchannels) {
return null;
}
return (
);
}, [hasSubchannels, onClickViewSubchannels]);
const onClickCreateSubchannel = React.useCallback(
() =>
pushModal(
,
),
[popModal, pushModal, threadInfo],
);
const createSubchannelsItem = React.useMemo(() => {
if (!canCreateSubchannels) {
return null;
}
return (
);
}, [canCreateSubchannels, onClickCreateSubchannel]);
const dispatchActionPromise = useDispatchActionPromise();
const callLeaveThread = useLeaveThread();
const onConfirmLeaveThread = React.useCallback(() => {
void dispatchActionPromise(
leaveThreadActionTypes,
callLeaveThread({ threadID: threadInfo.id }),
);
popModal();
}, [callLeaveThread, popModal, dispatchActionPromise, threadInfo.id]);
const onClickLeaveThread = React.useCallback(
() =>
pushModal(
,
),
[popModal, onConfirmLeaveThread, pushModal, threadInfo],
);
+ const canLeaveThread = useThreadHasPermission(
+ threadInfo,
+ threadPermissions.LEAVE_THREAD,
+ );
const leaveThreadItem = React.useMemo(() => {
- const canLeaveThread = threadHasPermission(
- threadInfo,
- threadPermissions.LEAVE_THREAD,
- );
if (!viewerIsMember(threadInfo) || !canLeaveThread) {
return null;
}
return (
);
- }, [onClickLeaveThread, threadInfo]);
+ }, [onClickLeaveThread, threadInfo, canLeaveThread]);
const onClickPromoteSidebarToThread = React.useCallback(
() =>
pushModal(
,
),
[pushModal, threadInfo, popModal, onPromoteSidebar],
);
const promoteSidebar = React.useMemo(() => {
return (
);
}, [onClickPromoteSidebarToThread]);
const onClickNotifications = React.useCallback(() => {
pushModal(
,
);
}, [popModal, pushModal, threadInfo.id]);
const notificationsItem = React.useMemo(() => {
if (!viewerIsMember(threadInfo)) {
return null;
}
return (
);
}, [onClickNotifications, threadInfo]);
const menuItems = React.useMemo(() => {
const separator =
;
const items = [
settingsItem,
notificationsItem,
membersItem,
threadMediaGalleryItem,
sidebarItem,
viewSubchannelsItem,
createSubchannelsItem,
leaveThreadItem && separator,
canPromoteSidebar && promoteSidebar,
leaveThreadItem,
];
return items.filter(Boolean);
}, [
settingsItem,
notificationsItem,
membersItem,
threadMediaGalleryItem,
sidebarItem,
viewSubchannelsItem,
promoteSidebar,
createSubchannelsItem,
leaveThreadItem,
canPromoteSidebar,
]);
const icon = React.useMemo(
() => ,
[],
);
return ;
}
export default ThreadMenu;