Skip to content

Commit bbdb24c

Browse files
committed
chore: cleanup if trees and add data test ids
1 parent 89a356d commit bbdb24c

File tree

11 files changed

+188
-118
lines changed

11 files changed

+188
-118
lines changed

ts/components/SessionWrapperModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type WithShowExitIcon = { showExitIcon?: boolean };
3737
const StyledModalHeader = styled(Flex)<{
3838
bigHeader?: boolean;
3939
scrolled: boolean;
40-
flowContentIntoHeader?: boolean;
4140
}>`
4241
position: relative;
4342
font-family: var(--font-default);

ts/components/conversation/right-panel/overlay/RightPanelMedia.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const RightPanelMedia = () => {
162162
>
163163
<HeaderTitle>{displayName || PubKey.shorten(selectedConvoKey)}</HeaderTitle>
164164
</Header>
165-
<PanelButtonGroup style={{ margin: '0 var(--margins-lg)' }} isSidePanel>
165+
<PanelButtonGroup style={{ margin: '0 var(--margins-lg)' }} isSidePanel={true}>
166166
<MediaGallery documents={documents} media={media} />
167167
</PanelButtonGroup>
168168
<SpacerLG />

ts/components/conversation/right-panel/overlay/message-info/OverlayMessageInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ export const OverlayMessageInfo = () => {
345345
)}
346346
<MessageInfo messageId={messageId} errors={messageInfo.errors} />
347347
<SpacerLG />
348-
<PanelButtonGroup style={{ margin: '0' }} isSidePanel>
348+
<PanelButtonGroup style={{ margin: '0' }} isSidePanel={true}>
349349
{/* CopyMessageBodyButton is always shown so the PanelButtonGroup always has at least one item */}
350350
{!isLegacyGroup && <ReplyToMessageButton messageId={messageId} />}
351351
{hasErrors && !isLegacyGroup && direction === 'outgoing' && (

ts/components/dialog/LocalizedPopupDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function LocalizedPopupDialog(props: LocalizedPopupDialogState) {
5353
props.overrideButtons.map(
5454
({ label, buttonType, onClick, closeAfterClick, dataTestId }) => (
5555
<SessionButton
56+
key={label.token}
5657
buttonType={buttonType || SessionButtonType.Simple}
5758
onClick={() => {
5859
onClick?.();

ts/components/dialog/user-settings/pages/user-pro/ProNonOriginatingPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ function ProPageHero({ variant }: VariantPageProps) {
4747
case 'renew':
4848
return <ProHeroImage heroText={tr('proAccessRenewStart')} />;
4949
case 'cancel':
50-
return <ProHeroImage noColors heroText={tr('proCancelSorry')} />;
50+
return <ProHeroImage heroText={tr('proCancelSorry')} noColors={true} />;
5151
case 'refund':
52-
return <ProHeroImage noColors heroText={tr('proRefundDescription')} />;
52+
return <ProHeroImage heroText={tr('proRefundDescription')} noColors={true} />;
5353
default:
5454
return assertUnreachable(variant, `Unknown pro non originating page variant: ${variant}`);
5555
}
@@ -376,7 +376,7 @@ function ProInfoBlockRefundSessionSupport() {
376376
}}
377377
>
378378
<ProInfoBlockRefundTitle>
379-
<Localizer token="proRefunding" />{' '}
379+
<Localizer token="proRefunding" />
380380
</ProInfoBlockRefundTitle>
381381
<Localizer token="proRefundRequestSessionSupport" />
382382
<ProInfoBlockRefundTitle>
@@ -398,7 +398,7 @@ function ProInfoBlockRefundGooglePlay() {
398398
}}
399399
>
400400
<ProInfoBlockRefundTitle>
401-
<Localizer token="proRefunding" />{' '}
401+
<Localizer token="proRefunding" />
402402
</ProInfoBlockRefundTitle>
403403
<Localizer token="proRefundRequestStorePolicies" platform={data.platformStrings.platform} />
404404
<ProInfoBlockRefundTitle>

ts/components/dialog/user-settings/pages/user-pro/ProSettingsPage.tsx

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isNumber } from 'lodash';
2-
import { MouseEventHandler, useCallback, useMemo, type ReactNode } from 'react';
2+
import { MouseEventHandler, SessionDataTestId, useCallback, useMemo, type ReactNode } from 'react';
33
import styled from 'styled-components';
44
import { useDispatch } from 'react-redux';
55
import { ModalBasicHeader } from '../../../../SessionWrapperModal';
@@ -46,6 +46,7 @@ import { proButtonProps } from '../../../SessionProInfoModal';
4646
import { useIsProGroupsAvailable } from '../../../../../hooks/useIsProAvailable';
4747
import { SessionSpinner } from '../../../../loading';
4848
import { SpacerMD } from '../../../../basic/Text';
49+
import { sleepFor } from '../../../../../session/utils/Promise';
4950

5051
// TODO: There are only 2 props here and both are passed to the nonorigin modal dispatch, can probably be in their own object
5152
type SectionProps = {
@@ -201,31 +202,25 @@ function ProNonProContinueButton({ returnToThisModalAction, centerAlign }: Secti
201202
const backendErrorButtons = useBackendErrorDialogButtons();
202203

203204
const handleClick = useCallback(() => {
204-
if (isError) {
205-
dispatch(
206-
updateLocalizedPopupDialog({
207-
title: { token: 'proStatusError' },
208-
description: { token: 'proStatusNetworkErrorDescription' },
209-
overrideButtons: backendErrorButtons,
210-
})
211-
);
212-
} else if (isLoading) {
213-
dispatch(
214-
updateLocalizedPopupDialog({
215-
title: { token: 'proStatusLoading' },
216-
description: { token: 'proStatusLoadingDescription' },
217-
})
218-
);
219-
} else {
220-
dispatch(
221-
userSettingsModal({
222-
userSettingsPage: 'proNonOriginating',
223-
nonOriginatingVariant: 'upgrade',
224-
overrideBackAction: returnToThisModalAction,
225-
centerAlign,
226-
})
227-
);
228-
}
205+
dispatch(
206+
isError
207+
? updateLocalizedPopupDialog({
208+
title: { token: 'proStatusError' },
209+
description: { token: 'proStatusNetworkErrorDescription' },
210+
overrideButtons: backendErrorButtons,
211+
})
212+
: isLoading
213+
? updateLocalizedPopupDialog({
214+
title: { token: 'proStatusLoading' },
215+
description: { token: 'proStatusLoadingDescription' },
216+
})
217+
: userSettingsModal({
218+
userSettingsPage: 'proNonOriginating',
219+
nonOriginatingVariant: 'upgrade',
220+
overrideBackAction: returnToThisModalAction,
221+
centerAlign,
222+
})
223+
);
229224
}, [dispatch, isLoading, isError, backendErrorButtons, centerAlign, returnToThisModalAction]);
230225

231226
if (!neverHadPro) {
@@ -273,7 +268,7 @@ const StatsLabel = styled.div<{ disabled?: boolean }>`
273268
const proBoxShadow = '0 4px 4px 0 rgba(0, 0, 0, 0.25)';
274269

275270
function ProStats() {
276-
const proLongerMessagesSent = Storage.get(SettingsKey.proLongerMessagesSent) || 3000;
271+
const proLongerMessagesSent = Storage.get(SettingsKey.proLongerMessagesSent) || 0;
277272
const proPinnedConversations = Storage.get(SettingsKey.proPinnedConversations) || 0;
278273
const proBadgesSent = Storage.get(SettingsKey.proBadgesSent) || 0;
279274
const proGroupsUpgraded = Storage.get(SettingsKey.proGroupsUpgraded) || 0;
@@ -475,10 +470,12 @@ function ProSettings({ returnToThisModalAction, centerAlign }: SectionProps) {
475470
function ProFeatureItem({
476471
textElement,
477472
iconElement,
473+
dataTestId,
478474
onClick,
479475
}: {
480476
iconElement: ReactNode;
481477
textElement: ReactNode;
478+
dataTestId: SessionDataTestId;
482479
onClick?: () => Promise<void>;
483480
}) {
484481
const isDarkTheme = useIsDarkTheme();
@@ -488,7 +485,7 @@ function ProFeatureItem({
488485
disabled={!onClick}
489486
// eslint-disable-next-line @typescript-eslint/no-misused-promises
490487
onClick={onClick}
491-
data-testid={'invalid-data-testid'}
488+
data-testid={dataTestId}
492489
isDarkTheme={isDarkTheme}
493490
defaultCursorWhenDisabled
494491
>
@@ -569,6 +566,7 @@ function ProFeatureIconElement({
569566

570567
function getProFeatures(userHasPro: boolean): Array<
571568
{
569+
dataTestId: SessionDataTestId;
572570
id:
573571
| 'proLongerMessages'
574572
| 'proUnlimitedPins'
@@ -581,6 +579,7 @@ function getProFeatures(userHasPro: boolean): Array<
581579
> {
582580
return [
583581
{
582+
dataTestId: 'longer-messages-pro-settings-menu-item',
584583
id: 'proLongerMessages',
585584
title: { token: 'proLongerMessages' as const },
586585
description: {
@@ -591,6 +590,7 @@ function getProFeatures(userHasPro: boolean): Array<
591590
unicode: LUCIDE_ICONS_UNICODE.MESSAGE_SQUARE,
592591
},
593592
{
593+
dataTestId: 'more-pins-pro-settings-menu-item',
594594
id: 'proUnlimitedPins',
595595
title: { token: 'proUnlimitedPins' as const },
596596
description: {
@@ -601,18 +601,21 @@ function getProFeatures(userHasPro: boolean): Array<
601601
unicode: LUCIDE_ICONS_UNICODE.PIN,
602602
},
603603
{
604+
dataTestId: 'animated-display-picture-pro-settings-menu-item',
604605
id: 'proAnimatedDisplayPictures',
605606
title: { token: 'proAnimatedDisplayPictures' as const },
606607
description: { token: 'proAnimatedDisplayPicturesDescription' as const },
607608
unicode: LUCIDE_ICONS_UNICODE.SQUARE_PLAY,
608609
},
609610
{
611+
dataTestId: 'badges-pro-settings-menu-item',
610612
id: 'proBadges',
611613
title: { token: 'proBadges' as const },
612614
description: { token: 'proBadgesDescription' as const },
613615
unicode: LUCIDE_ICONS_UNICODE.RECTANGLE_ELLIPSES,
614616
},
615617
{
618+
dataTestId: 'loads-more-pro-settings-menu-item',
616619
id: 'plusLoadsMore',
617620
title: { token: 'plusLoadsMore' as const },
618621
description: {
@@ -637,6 +640,7 @@ function ProFeatures() {
637640
{proFeatures.map((m, i) => {
638641
return (
639642
<ProFeatureItem
643+
dataTestId={m.dataTestId}
640644
onClick={
641645
m.id === 'plusLoadsMore'
642646
? async () => {
@@ -729,9 +733,7 @@ function ManageProCurrentAccess({ returnToThisModalAction, centerAlign }: Sectio
729733
// TODO: add logic to call libsession state
730734
function useRecoverProStatus() {
731735
const fetchAccess = useCallback(async () => {
732-
await new Promise(resolve => {
733-
setTimeout(resolve, 5000);
734-
});
736+
await sleepFor(5000);
735737
return { ok: false };
736738
}, []);
737739

@@ -749,69 +751,62 @@ function ManageProPreviousAccess({ returnToThisModalAction, centerAlign }: Secti
749751
const backendErrorButtons = useBackendErrorDialogButtons();
750752

751753
const handleClickRenew = useCallback(() => {
752-
if (isError) {
753-
dispatch(
754-
updateLocalizedPopupDialog({
755-
title: { token: 'proStatusError' },
756-
description: { token: 'proStatusRenewError' },
757-
overrideButtons: backendErrorButtons,
758-
})
759-
);
760-
} else if (isLoading) {
761-
dispatch(
762-
updateLocalizedPopupDialog({
763-
title: { token: 'proStatusLoading' },
764-
description: { token: 'checkingProStatusRenew' },
765-
})
766-
);
767-
} else {
768-
dispatch(
769-
userSettingsModal({
770-
userSettingsPage: 'proNonOriginating',
771-
nonOriginatingVariant: 'renew',
772-
overrideBackAction: returnToThisModalAction,
773-
centerAlign,
774-
})
775-
);
776-
}
754+
dispatch(
755+
isError
756+
? updateLocalizedPopupDialog({
757+
title: { token: 'proStatusError' },
758+
description: { token: 'proStatusRenewError' },
759+
overrideButtons: backendErrorButtons,
760+
})
761+
: isLoading
762+
? updateLocalizedPopupDialog({
763+
title: { token: 'proStatusLoading' },
764+
description: { token: 'checkingProStatusRenew' },
765+
})
766+
: userSettingsModal({
767+
userSettingsPage: 'proNonOriginating',
768+
nonOriginatingVariant: 'renew',
769+
overrideBackAction: returnToThisModalAction,
770+
centerAlign,
771+
})
772+
);
777773
}, [dispatch, isLoading, isError, backendErrorButtons, centerAlign, returnToThisModalAction]);
778774

779775
const handleClickRecover = useCallback(async () => {
780776
const result = await fetchRecoverAccess();
781777

782778
if (result.ok) {
783-
dispatch(
779+
return dispatch(
784780
updateLocalizedPopupDialog({
785781
title: { token: 'proAccessRestored' },
786782
description: { token: 'proAccessRestoredDescription' },
787783
})
788784
);
789-
} else {
790-
dispatch(
791-
updateLocalizedPopupDialog({
792-
title: { token: 'proAccessNotFound' },
793-
description: { token: 'proAccessNotFoundDescription' },
794-
overrideButtons: [
795-
{
796-
label: { token: 'helpSupport' },
797-
dataTestId: 'pro-backend-error-support-button',
798-
onClick: () => {
799-
showLinkVisitWarningDialog(
800-
'https://sessionapp.zendesk.com/hc/sections/4416517450649-Support',
801-
dispatch
802-
);
803-
},
804-
closeAfterClick: true,
805-
},
806-
{
807-
label: { token: 'close' },
808-
dataTestId: 'modal-close-button',
809-
closeAfterClick: true,
810-
},
811-
],
812-
})
813-
);
814785
}
786+
return dispatch(
787+
updateLocalizedPopupDialog({
788+
title: { token: 'proAccessNotFound' },
789+
description: { token: 'proAccessNotFoundDescription' },
790+
overrideButtons: [
791+
{
792+
label: { token: 'helpSupport' },
793+
dataTestId: 'pro-backend-error-support-button',
794+
onClick: () => {
795+
showLinkVisitWarningDialog(
796+
'https://sessionapp.zendesk.com/hc/sections/4416517450649-Support',
797+
dispatch
798+
);
799+
},
800+
closeAfterClick: true,
801+
},
802+
{
803+
label: { token: 'close' },
804+
dataTestId: 'modal-close-button',
805+
closeAfterClick: true,
806+
},
807+
],
808+
})
809+
);
815810
}, [dispatch, fetchRecoverAccess]);
816811

817812
if (!userHasExpiredPro) {
@@ -908,14 +903,18 @@ function PageHero() {
908903
overrideButtons: backendErrorButtons,
909904
})
910905
);
911-
} else if (isLoading) {
906+
return;
907+
}
908+
909+
if (isLoading) {
912910
dispatch(
913911
updateLocalizedPopupDialog({
914912
title: { token: 'proStatusLoading' },
915913
description: { token: 'proStatusLoadingDescription' },
916914
})
917915
);
918916
}
917+
// Do nothing if not error or loading
919918
}, [dispatch, isLoading, isError, backendErrorButtons]);
920919

921920
const heroStatusText = useMemo(() => {

ts/components/leftpane/ActionsPanel.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,10 @@ function useUpdateBadgeCount() {
163163
function useDebugThemeSwitch() {
164164
useKey(
165165
(event: KeyboardEvent) => {
166-
return event.ctrlKey && event.key === 't';
166+
return isDevProd() && event.ctrlKey && event.key === 't';
167167
},
168168
() => {
169-
if (isDevProd()) {
170-
void handleThemeSwitch();
171-
}
169+
void handleThemeSwitch();
172170
}
173171
);
174172
}
@@ -197,12 +195,10 @@ function DebugMenuModalButton() {
197195

198196
useKey(
199197
(event: KeyboardEvent) => {
200-
return event.ctrlKey && event.key === 'd';
198+
return isDevProd() && event.ctrlKey && event.key === 'd';
201199
},
202200
() => {
203-
if (isDevProd()) {
204-
dispatch(updateDebugMenuModal(debugMenuModalState ? null : {}));
205-
}
201+
dispatch(updateDebugMenuModal(debugMenuModalState ? null : {}));
206202
}
207203
);
208204

0 commit comments

Comments
 (0)