|
| 1 | +import { createPortal } from 'react-dom'; |
| 2 | +import { contextMenu } from 'react-contexify'; |
| 3 | +import type { ReactNode } from 'react'; |
1 | 4 | import styled, { CSSProperties } from 'styled-components';
|
| 5 | + |
2 | 6 | import { openConversationWithMessages } from '../../../../state/ducks/conversations';
|
3 | 7 | import { Avatar, AvatarSize } from '../../../avatar/Avatar';
|
4 | 8 | import { useShowUserDetailsCbFromConversation } from '../../../menuAndSettingsHooks/useShowUserDetailsCb';
|
5 | 9 | import { ContactName } from '../../../conversation/ContactName/ContactName';
|
| 10 | +import { MemoConversationListItemContextMenu } from '../../../menu/ConversationListItemContextMenu'; |
| 11 | +import { ContextConversationProvider } from '../../../../contexts/ConvoIdContext'; |
| 12 | + |
| 13 | +const Portal = ({ children }: { children: ReactNode }) => { |
| 14 | + return createPortal(children, document.querySelector('.inbox.index') as Element); |
| 15 | +}; |
6 | 16 |
|
7 | 17 | type Props = { id: string; displayName?: string; style: CSSProperties };
|
8 | 18 |
|
@@ -56,23 +66,35 @@ export const ContactRowBreak = (props: { char: string; key: string; style: CSSPr
|
56 | 66 |
|
57 | 67 | export const ContactRow = (props: Props) => {
|
58 | 68 | const { id, style } = props;
|
| 69 | + const triggerId = `contact-row-${id}-ctxmenu`; |
59 | 70 |
|
60 | 71 | return (
|
61 |
| - <StyledRowContainer |
62 |
| - style={style} |
63 |
| - // eslint-disable-next-line @typescript-eslint/no-misused-promises |
64 |
| - onClick={async () => openConversationWithMessages({ conversationKey: id, messageId: null })} |
65 |
| - > |
66 |
| - <AvatarItem id={id} /> |
67 |
| - <ContactName |
68 |
| - data-testid="module-conversation__user__profile-name" |
69 |
| - pubkey={id} |
70 |
| - contactNameContext="contact-list-row" |
71 |
| - extraNameStyle={{ |
72 |
| - color: 'var(--text-primary-color)', |
73 |
| - fontSize: 'var(--font-size-lg)', |
| 72 | + <ContextConversationProvider value={id}> |
| 73 | + <StyledRowContainer |
| 74 | + style={style} |
| 75 | + // eslint-disable-next-line @typescript-eslint/no-misused-promises |
| 76 | + onClick={async () => openConversationWithMessages({ conversationKey: id, messageId: null })} |
| 77 | + onContextMenu={e => { |
| 78 | + contextMenu.show({ |
| 79 | + id: triggerId, |
| 80 | + event: e, |
| 81 | + }); |
74 | 82 | }}
|
75 |
| - /> |
76 |
| - </StyledRowContainer> |
| 83 | + > |
| 84 | + <AvatarItem id={id} /> |
| 85 | + <ContactName |
| 86 | + data-testid="module-conversation__user__profile-name" |
| 87 | + pubkey={id} |
| 88 | + contactNameContext="contact-list-row" |
| 89 | + extraNameStyle={{ |
| 90 | + color: 'var(--text-primary-color)', |
| 91 | + fontSize: 'var(--font-size-lg)', |
| 92 | + }} |
| 93 | + /> |
| 94 | + <Portal> |
| 95 | + <MemoConversationListItemContextMenu triggerId={triggerId} /> |
| 96 | + </Portal> |
| 97 | + </StyledRowContainer> |
| 98 | + </ContextConversationProvider> |
77 | 99 | );
|
78 | 100 | };
|
0 commit comments