Simplify about string logic
This commit is contained in:
parent
25d206e4f7
commit
c1b5811c39
3 changed files with 3 additions and 93 deletions
|
@ -36,7 +36,6 @@ import type { ShowToastAction } from '../state/ducks/toast';
|
||||||
import { getEmojiData, unifiedToEmoji } from './emoji/lib';
|
import { getEmojiData, unifiedToEmoji } from './emoji/lib';
|
||||||
import { assertDev } from '../util/assert';
|
import { assertDev } from '../util/assert';
|
||||||
import { missingCaseError } from '../util/missingCaseError';
|
import { missingCaseError } from '../util/missingCaseError';
|
||||||
import { sanitizeAboutText } from '../util/getAboutText';
|
|
||||||
import { ConfirmationDialog } from './ConfirmationDialog';
|
import { ConfirmationDialog } from './ConfirmationDialog';
|
||||||
import { ContextMenu } from './ContextMenu';
|
import { ContextMenu } from './ContextMenu';
|
||||||
import { UsernameLinkModalBody } from './UsernameLinkModalBody';
|
import { UsernameLinkModalBody } from './UsernameLinkModalBody';
|
||||||
|
@ -210,7 +209,6 @@ export function ProfileEditor({
|
||||||
});
|
});
|
||||||
const [isResettingUsername, setIsResettingUsername] = useState(false);
|
const [isResettingUsername, setIsResettingUsername] = useState(false);
|
||||||
const [isResettingUsernameLink, setIsResettingUsernameLink] = useState(false);
|
const [isResettingUsernameLink, setIsResettingUsernameLink] = useState(false);
|
||||||
const [isInvalidAboutText, setIsInvalidAboutText] = useState(false);
|
|
||||||
|
|
||||||
// Reset username edit state when leaving
|
// Reset username edit state when leaving
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -497,14 +495,6 @@ export function ProfileEditor({
|
||||||
<Button
|
<Button
|
||||||
disabled={shouldDisableSave}
|
disabled={shouldDisableSave}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
|
||||||
sanitizeAboutText(stagedProfile.aboutText) !==
|
|
||||||
stagedProfile.aboutText
|
|
||||||
) {
|
|
||||||
setIsInvalidAboutText(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setFullBio({
|
setFullBio({
|
||||||
aboutEmoji: stagedProfile.aboutEmoji,
|
aboutEmoji: stagedProfile.aboutEmoji,
|
||||||
aboutText: stagedProfile.aboutText,
|
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 && (
|
{isResettingUsernameLink && (
|
||||||
<ConfirmationDialog
|
<ConfirmationDialog
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
|
|
|
@ -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'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,20 +1,12 @@
|
||||||
// Copyright 2023 Signal Messenger, LLC
|
// Copyright 2023 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import type { LocalizerType } from '../types/Util';
|
|
||||||
import type { ConversationAttributesType } from '../model-types';
|
import type { ConversationAttributesType } from '../model-types';
|
||||||
|
|
||||||
export function sanitizeAboutText(
|
|
||||||
text: string | undefined
|
|
||||||
): string | undefined {
|
|
||||||
return text?.replace(/[✓✔☑√⛉⛊⛛]/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAboutText(
|
export function getAboutText(
|
||||||
attributes: Pick<ConversationAttributesType, 'about' | 'aboutEmoji'>,
|
attributes: Pick<ConversationAttributesType, 'about' | 'aboutEmoji'>
|
||||||
i18n: LocalizerType = window.i18n
|
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
const text = sanitizeAboutText(attributes.about);
|
const text = attributes.about;
|
||||||
|
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -26,7 +18,7 @@ export function getAboutText(
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i18n('icu:message--getNotificationText--text-with-emoji', {
|
return window.i18n('icu:message--getNotificationText--text-with-emoji', {
|
||||||
text,
|
text,
|
||||||
emoji,
|
emoji,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue