menu item creation moved to getPinConversationMenuItem

pull/1770/head
Brice-W 4 years ago
parent ff7f201e04
commit 14cecb1216

@ -15,7 +15,7 @@ import {
getInviteContactMenuItem,
getLeaveGroupMenuItem,
getMarkAllReadMenuItem,
MenuItemPinConversation,
getPinConversationMenuItem,
} from './Menu';
export type PropsContextConversationItem = {
@ -46,15 +46,11 @@ export const ConversationListItemContextMenu = (props: PropsContextConversationI
const isGroup = type === 'group';
const isMessagesSection = useSelector(getFocusedSection) === SectionType.Message;
const pinMenuItem =
isMessagesSection && window.lokiFeatureFlags.enablePinConversations ? (
<MenuItemPinConversation conversationId={conversationId} />
) : null;
return (
<>
<Menu id={triggerId} animation={animation.fade}>
{pinMenuItem}
{getPinConversationMenuItem(isMessagesSection, conversationId)}
{getBlockMenuItem(isMe, type === ConversationTypeEnum.PRIVATE, isBlocked, conversationId)}
{getCopyMenuItem(isPublic, isGroup, conversationId)}
{getMarkAllReadMenuItem(conversationId)}

@ -130,28 +130,32 @@ export interface PinConversationMenuItemProps {
conversationId: string;
}
export const MenuItemPinConversation = (
props: PinConversationMenuItemProps
export const getPinConversationMenuItem = (
isMessagesSection: boolean,
conversationId: string
): JSX.Element | null => {
const { conversationId } = props;
const conversation = getConversationController().get(conversationId);
const isPinned = conversation.isPinned();
const nbOfAlreadyPinnedConvos = useSelector(getNumberOfPinnedConversations);
const togglePinConversation = async () => {
if ((!isPinned && nbOfAlreadyPinnedConvos < maxNumberOfPinnedConversations) || isPinned) {
await conversation.setIsPinned(!isPinned);
} else {
ToastUtils.pushToastWarning(
'pinConversationLimitToast',
window.i18n('pinConversationLimitTitle'),
window.i18n('pinConversationLimitToastDescription', maxNumberOfPinnedConversations)
);
}
};
if (isMessagesSection && window.lokiFeatureFlags.enablePinConversations) {
const conversation = getConversationController().get(conversationId);
const isPinned = conversation.isPinned();
const nbOfAlreadyPinnedConvos = useSelector(getNumberOfPinnedConversations);
const togglePinConversation = async () => {
if ((!isPinned && nbOfAlreadyPinnedConvos < maxNumberOfPinnedConversations) || isPinned) {
await conversation.setIsPinned(!isPinned);
} else {
ToastUtils.pushToastWarning(
'pinConversationLimitToast',
window.i18n('pinConversationLimitTitle'),
window.i18n('pinConversationLimitToastDescription', maxNumberOfPinnedConversations)
);
}
};
const menuText = isPinned ? window.i18n('unpinConversation') : window.i18n('pinConversation');
return <Item onClick={togglePinConversation}>{menuText}</Item>;
const menuText = isPinned ? window.i18n('unpinConversation') : window.i18n('pinConversation');
return <Item onClick={togglePinConversation}>{menuText}</Item>;
} else {
return null;
}
};
export function getDeleteContactMenuItem(

Loading…
Cancel
Save