Simplify about string logic

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-10-08 16:55:18 -05:00 committed by GitHub
parent 7964f70c44
commit 9d785b2718
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 93 deletions

View file

@ -36,7 +36,6 @@ import type { ShowToastAction } from '../state/ducks/toast';
import { getEmojiData, unifiedToEmoji } from './emoji/lib';
import { assertDev } from '../util/assert';
import { missingCaseError } from '../util/missingCaseError';
import { sanitizeAboutText } from '../util/getAboutText';
import { ConfirmationDialog } from './ConfirmationDialog';
import { ContextMenu } from './ContextMenu';
import { UsernameLinkModalBody } from './UsernameLinkModalBody';
@ -210,7 +209,6 @@ export function ProfileEditor({
});
const [isResettingUsername, setIsResettingUsername] = useState(false);
const [isResettingUsernameLink, setIsResettingUsernameLink] = useState(false);
const [isInvalidAboutText, setIsInvalidAboutText] = useState(false);
// Reset username edit state when leaving
useEffect(() => {
@ -497,14 +495,6 @@ export function ProfileEditor({
<Button
disabled={shouldDisableSave}
onClick={() => {
if (
sanitizeAboutText(stagedProfile.aboutText) !==
stagedProfile.aboutText
) {
setIsInvalidAboutText(true);
return;
}
setFullBio({
aboutEmoji: stagedProfile.aboutEmoji,
aboutText: stagedProfile.aboutText,
@ -778,25 +768,6 @@ export function ProfileEditor({
/>
)}
{isInvalidAboutText && (
<ConfirmationDialog
dialogName="ProfileEditorModal.invalidAboutText"
title={i18n('icu:ProfileEditor__invalid-about__title')}
cancelButtonVariant={ButtonVariant.Primary}
cancelText={i18n('icu:Confirmation--confirm')}
i18n={i18n}
onClose={() => {
setStagedProfile(profileData => ({
...profileData,
aboutText: sanitizeAboutText(profileData?.aboutText),
}));
setIsInvalidAboutText(false);
}}
>
{i18n('icu:ProfileEditor__invalid-about__body')}
</ConfirmationDialog>
)}
{isResettingUsernameLink && (
<ConfirmationDialog
i18n={i18n}

View file

@ -1,53 +0,0 @@
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import enMessages from '../../../_locales/en/messages.json';
import { getAboutText } from '../../util/getAboutText';
import { setupI18n } from '../../util/setupI18n';
const i18n = setupI18n('en', enMessages);
describe('getAboutText', () => {
it('returns undefined when there is no text', () => {
assert.isUndefined(getAboutText({}, i18n));
});
it('returns text when there is text, but not emoji', () => {
assert.strictEqual(
getAboutText(
{
about: 'hello',
},
i18n
),
'hello'
);
});
it('returns text and emoji', () => {
assert.strictEqual(
getAboutText(
{
about: 'hello',
aboutEmoji: '😁',
},
i18n
),
'😁 hello'
);
});
it('simplifies text', () => {
assert.strictEqual(
getAboutText(
{
about: '✓✔☑√⛉⛊⛛hello',
},
i18n
),
'hello'
);
});
});

View file

@ -1,20 +1,12 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { LocalizerType } from '../types/Util';
import type { ConversationAttributesType } from '../model-types';
export function sanitizeAboutText(
text: string | undefined
): string | undefined {
return text?.replace(/[✓✔☑√⛉⛊⛛]/g, '');
}
export function getAboutText(
attributes: Pick<ConversationAttributesType, 'about' | 'aboutEmoji'>,
i18n: LocalizerType = window.i18n
attributes: Pick<ConversationAttributesType, 'about' | 'aboutEmoji'>
): string | undefined {
const text = sanitizeAboutText(attributes.about);
const text = attributes.about;
if (!text) {
return undefined;
@ -26,7 +18,7 @@ export function getAboutText(
return text;
}
return i18n('icu:message--getNotificationText--text-with-emoji', {
return window.i18n('icu:message--getNotificationText--text-with-emoji', {
text,
emoji,
});