Skip to content

Commit bb42d83

Browse files
committed
chore: cleanup PR before review
1 parent 508d819 commit bb42d83

22 files changed

+346
-183
lines changed

ts/components/SessionQRCode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function SessionQRCode(props: SessionQRCodeProps) {
123123
$alignItems="center"
124124
size={size}
125125
id={id}
126-
title={tr('download')}
126+
title={tr('fullScreenToggle')}
127127
aria-label={ariaLabel || 'QR code'}
128128
onClick={(event: MouseEvent<HTMLDivElement>) => {
129129
event.preventDefault();

ts/components/SessionWrapperModal.tsx

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ import { LUCIDE_ICONS_UNICODE } from './icon/lucide';
1515
import { IsModalScrolledContext, useIsModalScrolled } from '../contexts/IsModalScrolledContext';
1616
import { OnModalCloseContext, useOnModalClose } from '../contexts/OnModalCloseContext';
1717

18+
type WithExtraLeftButton = {
19+
/**
20+
* A button to be displayed on the left side of the header title.
21+
* If all you want is a close button, use showExitIcon instead.
22+
* Check other usages to use the correct icon size and styling.
23+
*/
24+
extraLeftButton?: ReactNode;
25+
};
26+
type WithExtraRightButton = {
27+
/**
28+
* A button to be displayed on the right side of the header title.
29+
* Check other usages to use the correct icon size and styling.
30+
*/
31+
extraRightButton?: ReactNode;
32+
};
33+
type WithShowExitIcon = { showExitIcon?: boolean };
34+
1835
const StyledModalHeader = styled(Flex)<{ bigHeader?: boolean; scrolled: boolean }>`
1936
position: relative;
2037
font-family: var(--font-default);
@@ -53,12 +70,13 @@ export enum WrapperModalWidth {
5370
const StyledModal = styled.div<{
5471
$contentMaxWidth?: WrapperModalWidth;
5572
$contentMinWidth?: WrapperModalWidth;
56-
padding?: string;
57-
topAnchor?: string;
73+
$padding?: string;
74+
$topAnchor: ModalTopAnchor;
5875
}>`
5976
position: absolute;
60-
top: ${props => (props.topAnchor ? props.topAnchor : '15vh')};
61-
max-height: 80vh;
77+
top: ${props => props.$topAnchor};
78+
max-height: ${props => `calc(100vh - ${props.$topAnchor} - 5vh)`};
79+
6280
animation: fadein var(--default-duration);
6381
z-index: 150;
6482
max-width: ${props =>
@@ -75,8 +93,8 @@ const StyledModal = styled.div<{
7593
7694
margin: auto auto;
7795
padding: ${props =>
78-
props.padding
79-
? props.padding
96+
props.$padding
97+
? props.$padding
8098
: // Note: no padding by default as it depends on what is rendered, see the ModalMap before you change something here
8199
'0'};
82100
@@ -187,15 +205,11 @@ export type SessionWrapperModalType = {
187205

188206
function ExtraSpacerLeft({
189207
extraRightButton,
190-
leftButton,
208+
extraLeftButton,
191209
showExitIcon,
192-
}: {
193-
showExitIcon?: boolean;
194-
leftButton?: ReactNode;
195-
extraRightButton?: ReactNode;
196-
}) {
210+
}: WithShowExitIcon & WithExtraRightButton & WithExtraLeftButton) {
197211
// if we have two button on the right, and one on the left, we need to add one spacer
198-
if (extraRightButton && showExitIcon && leftButton) {
212+
if (extraRightButton && showExitIcon && extraLeftButton) {
199213
return <SpacerLG />;
200214
}
201215
if (extraRightButton && showExitIcon) {
@@ -209,7 +223,7 @@ function ExtraSpacerLeft({
209223
}
210224
// starting here, showExitIcon is false.
211225

212-
if (extraRightButton && leftButton) {
226+
if (extraRightButton && extraLeftButton) {
213227
// if we have one button on each sides, no need for a spacer,
214228
return null;
215229
}
@@ -223,23 +237,18 @@ function ExtraSpacerLeft({
223237
*/
224238
export const ModalBasicHeader = ({
225239
showExitIcon,
226-
leftButton,
240+
extraLeftButton,
227241
title,
228242
bigHeader,
229243
modalHeaderDataTestId,
230244
extraRightButton,
231-
}: {
232-
title?: ReactNode;
233-
showExitIcon?: boolean;
234-
leftButton?: ReactNode;
235-
/**
236-
* A button to be displayed on the right side of the header.
237-
* If all you want is a close button, use showExitIcon instead.
238-
*/
239-
extraRightButton?: ReactNode;
240-
bigHeader?: boolean;
241-
modalHeaderDataTestId?: SessionDataTestId;
242-
}) => {
245+
}: WithShowExitIcon &
246+
WithExtraRightButton &
247+
WithExtraLeftButton & {
248+
title?: ReactNode;
249+
bigHeader?: boolean;
250+
modalHeaderDataTestId?: SessionDataTestId;
251+
}) => {
243252
const htmlDirection = useHTMLDirection();
244253

245254
const onClose = useOnModalClose();
@@ -267,13 +276,14 @@ export const ModalBasicHeader = ({
267276
{/* Note: add a spacer if no left button is set but we have an exit icon */}
268277
<ExtraSpacerLeft
269278
showExitIcon={showExitIcon}
270-
leftButton={leftButton}
279+
extraLeftButton={extraLeftButton}
271280
extraRightButton={extraRightButton}
272281
/>
282+
{extraLeftButton}
273283
</Flex>
274284
<StyledTitle
275285
bigHeader={bigHeader}
276-
tabIndex={!showExitIcon && !leftButton ? 0 : undefined}
286+
tabIndex={!showExitIcon && !extraLeftButton ? 0 : undefined}
277287
data-testid="modal-heading"
278288
>
279289
{title}
@@ -371,9 +381,9 @@ export const SessionWrapperModal = (props: SessionWrapperModalType & { onClose?:
371381
ref={modalRef}
372382
$contentMaxWidth={$contentMaxWidth}
373383
$contentMinWidth={$contentMinWidth}
374-
padding={padding}
384+
$padding={padding}
375385
style={style}
376-
topAnchor={topAnchor}
386+
$topAnchor={topAnchor ?? '15vh'}
377387
>
378388
{props.headerChildren ? props.headerChildren : null}
379389

ts/components/avatar/CrownIcon.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ export const CrownIcon = () => {
2626
iconColor={iconColor}
2727
iconSize={'small'}
2828
iconType="crown"
29-
iconPadding="1px 0px 1px 1px"
29+
iconPadding="2px"
30+
style={{
31+
position: 'absolute',
32+
top: '50%',
33+
left: '50%',
34+
transform: 'translate(-50%, -50%)',
35+
}}
3036
/>
3137
</CrownWrapper>
3238
);

ts/components/conversation/ContactName/ContactName.tsx

Lines changed: 132 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,132 @@ import { ProIconButton } from '../../buttons/ProButton';
1919
import { useMessageIdFromContext } from '../../../contexts/MessageIdContext';
2020
import { useMessageDirection } from '../../../state/selectors';
2121
import { useShowUserDetailsCbFromConversation } from '../../menuAndSettingsHooks/useShowUserDetailsCb';
22+
import { assertUnreachable } from '../../../types/sqlSharedTypes';
2223

23-
const boldProfileNameCtx: Array<ContactNameContext> = [
24-
'conversation-list-item',
25-
'quoted-message-composition',
26-
'message-author',
27-
'message-info-author',
28-
'member-list-item',
29-
'contact-list-row',
30-
];
31-
32-
const showPubkeyCtx: Array<ContactNameContext> = ['message-author'];
33-
34-
const ntsIsYouCtx: Array<ContactNameContext> = [
35-
'message-author',
36-
'quote-author',
37-
'quoted-message-composition',
38-
'message-search-result',
39-
'react-list-modal',
40-
'member-list-item',
41-
];
42-
43-
const forceSingleLineCtx: Array<ContactNameContext> = [
44-
'message-info-author',
45-
'member-list-item',
46-
'contact-list-row',
47-
];
24+
/**
25+
* In some contexts, we want to bold the name of the contact.
26+
*/
27+
function isBoldProfileNameCtx(ctx: ContactNameContext) {
28+
// We are doing this as a switch instead of an array so we have to be explicit anytime we add a new context,
29+
// thanks to the assertUnreachable below
30+
switch (ctx) {
31+
case 'conversation-list-item':
32+
case 'quoted-message-composition':
33+
case 'message-author':
34+
case 'message-info-author':
35+
case 'member-list-item':
36+
case 'contact-list-row':
37+
return true;
38+
case 'quote-author':
39+
case 'conversation-list-item-search':
40+
case 'react-list-modal':
41+
case 'message-search-result':
42+
return false;
43+
default:
44+
assertUnreachable(ctx, 'isBoldProfileNameCtx');
45+
throw new Error('isBoldProfileNameCtx: unreachable');
46+
}
47+
}
48+
49+
/**
50+
* In some contexts, we want to show the pubkey of the contact.
51+
*/
52+
function isShowPubkeyCtx(ctx: ContactNameContext) {
53+
// We are doing this as a switch instead of an array so we have to be explicit anytime we add a new context,
54+
// thanks to the assertUnreachable below
55+
switch (ctx) {
56+
case 'message-author':
57+
case 'message-info-author':
58+
return true;
59+
case 'member-list-item':
60+
case 'contact-list-row':
61+
case 'quote-author':
62+
case 'conversation-list-item':
63+
case 'quoted-message-composition':
64+
case 'conversation-list-item-search':
65+
case 'react-list-modal':
66+
case 'message-search-result':
67+
return false;
68+
default:
69+
assertUnreachable(ctx, 'isShowPubkeyCtx');
70+
throw new Error('isShowPubkeyCtx: unreachable');
71+
}
72+
}
73+
74+
/**
75+
* In some contexts, we want to rename "Note To Self" to "You".
76+
*/
77+
function isShowNtsIsYouCtx(ctx: ContactNameContext) {
78+
// We are doing this as a switch instead of an array so we have to be explicit anytime we add a new context,
79+
// thanks to the assertUnreachable below
80+
switch (ctx) {
81+
case 'message-author':
82+
case 'quote-author':
83+
case 'quoted-message-composition':
84+
case 'react-list-modal':
85+
case 'message-search-result':
86+
case 'member-list-item':
87+
return true;
88+
case 'message-info-author':
89+
case 'contact-list-row':
90+
case 'conversation-list-item':
91+
case 'conversation-list-item-search':
92+
return false;
93+
default:
94+
assertUnreachable(ctx, 'isShowNtsIsYouCtx');
95+
throw new Error('isShowNtsIsYouCtx: unreachable');
96+
}
97+
}
98+
99+
/**
100+
* Usually, we'd allow the name to be multiline. but in some contexts we want to force it to be single line.
101+
*/
102+
function isForceSingleLineCtx(ctx: ContactNameContext) {
103+
// We are doing this as a switch instead of an array so we have to be explicit anytime we add a new context,
104+
// thanks to the assertUnreachable below
105+
switch (ctx) {
106+
case 'message-info-author':
107+
case 'member-list-item':
108+
case 'contact-list-row':
109+
return true;
110+
case 'message-author':
111+
case 'quote-author':
112+
case 'quoted-message-composition':
113+
case 'react-list-modal':
114+
case 'message-search-result':
115+
case 'conversation-list-item':
116+
case 'conversation-list-item-search':
117+
return false;
118+
default:
119+
assertUnreachable(ctx, 'isForceSingleLineCtx');
120+
throw new Error('isForceSingleLineCtx: unreachable');
121+
}
122+
}
123+
124+
/**
125+
* Usually, we'd allow the name to be multiline. but in some contexts we want to force it to be single line.
126+
*/
127+
function isShowUPMOnClickCtx(ctx: ContactNameContext) {
128+
// We are doing this as a switch instead of an array so we have to be explicit anytime we add a new context,
129+
// thanks to the assertUnreachable below
130+
switch (ctx) {
131+
case 'message-info-author':
132+
return true;
133+
case 'member-list-item':
134+
case 'contact-list-row':
135+
case 'message-author':
136+
case 'quote-author':
137+
case 'quoted-message-composition':
138+
case 'react-list-modal':
139+
case 'message-search-result':
140+
case 'conversation-list-item':
141+
case 'conversation-list-item-search':
142+
return false;
143+
default:
144+
assertUnreachable(ctx, 'isForceSingleLineCtx');
145+
throw new Error('isForceSingleLineCtx: unreachable');
146+
}
147+
}
48148

49149
const commonNameStyles: CSSProperties = {
50150
minWidth: 0,
@@ -62,8 +162,6 @@ const boldStyles: CSSProperties = {
62162
fontWeight: 'bold',
63163
};
64164

65-
const contactNameContextShowUPM: Array<ContactNameContext> = ['message-info-author'];
66-
67165
export const ContactName = ({
68166
pubkey,
69167
module,
@@ -99,21 +197,19 @@ export const ContactName = ({
99197
const msgDirection = useMessageDirection(msgId);
100198

101199
const displayName = isMe
102-
? // we want to show "You" instead of Note to Self in some places (like quotes)
103-
ntsIsYouCtx.includes(contactNameContext)
104-
? tr('you')
105-
: tr('noteToSelf')
106-
: // we want to show the nickname in brackets if a nickname is set for search results
200+
? // we want to show "You" instead of "Note to Self" in some places (like quotes)
201+
tr(isShowNtsIsYouCtx(contactNameContext) ? 'you' : 'noteToSelf')
202+
: // we want to show the realName in brackets if a nickname is set for search results
107203
contactNameContext === 'conversation-list-item-search' && nickname && realName
108204
? `${nickname} (${realName})`
109205
: noFallback;
110206

111207
const shouldShowShortenPkAsName = !displayName;
112208

113209
const shouldShowPubkey =
114-
!shouldShowShortenPkAsName && isPublic && showPubkeyCtx.includes(contactNameContext);
115-
const boldProfileName = boldProfileNameCtx.includes(contactNameContext);
116-
const forceSingleLine = forceSingleLineCtx.includes(contactNameContext);
210+
!shouldShowShortenPkAsName && isPublic && isShowPubkeyCtx(contactNameContext);
211+
const boldProfileName = isBoldProfileNameCtx(contactNameContext);
212+
const forceSingleLine = isForceSingleLineCtx(contactNameContext);
117213

118214
const displayedName = shouldShowShortenPkAsName ? shortPubkey : displayName;
119215

@@ -163,10 +259,7 @@ export const ContactName = ({
163259
maxWidth: '100%',
164260
...style,
165261
}}
166-
onClick={
167-
(contactNameContextShowUPM.includes(contactNameContext) && showConversationSettingsCb) ||
168-
undefined
169-
}
262+
onClick={(isShowUPMOnClickCtx(contactNameContext) && showConversationSettingsCb) || undefined}
170263
>
171264
{displayedName ? (
172265
<div style={mergedNameStyle} className={`${prefix}__profile-name`}>

ts/components/dialog/SessionConfirm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ import { ModalDescription } from './shared/ModalDescriptionContainer';
1818
import { tr } from '../../localization/localeTools';
1919
import { ModalFlexContainer } from './shared/ModalFlexContainer';
2020

21-
export interface SessionConfirmDialogProps {
21+
export type SessionConfirmDialogProps = {
2222
i18nMessage?: LocalizerProps;
2323
title?: string;
2424
radioOptions?: SessionRadioItems;
25-
onOk?: any;
2625
onClose?: any;
27-
closeAfterInput?: boolean;
2826

2927
/**
3028
* function to run on ok click. Closes modal after execution by default
@@ -49,7 +47,7 @@ export interface SessionConfirmDialogProps {
4947
closeTheme?: SessionButtonColor;
5048
showExitIcon?: boolean | undefined;
5149
conversationId?: string;
52-
}
50+
};
5351

5452
export const SessionConfirm = (props: SessionConfirmDialogProps) => {
5553
const {

0 commit comments

Comments
 (0)