signal-desktop/ts/components/SharedGroupNames.tsx

97 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-04-16 15:51:26 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
2021-04-16 15:51:26 +00:00
import { take } from 'lodash';
import { Intl } from './Intl';
import type { LocalizerType } from '../types/Util';
2023-04-20 17:03:43 +00:00
import { UserText } from './UserText';
2021-04-16 15:51:26 +00:00
type PropsType = {
i18n: LocalizerType;
nameClassName?: string;
sharedGroupNames: ReadonlyArray<string>;
2021-04-16 15:51:26 +00:00
};
2022-11-18 00:45:19 +00:00
export function SharedGroupNames({
2021-04-16 15:51:26 +00:00
i18n,
nameClassName,
sharedGroupNames,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2021-04-16 15:51:26 +00:00
const firstThreeGroups = take(sharedGroupNames, 3).map((group, i) => (
// We cannot guarantee uniqueness of group names
// eslint-disable-next-line react/no-array-index-key
<strong key={i} className={nameClassName}>
2023-04-20 17:03:43 +00:00
<UserText text={group} />
2021-04-16 15:51:26 +00:00
</strong>
));
if (sharedGroupNames.length >= 5) {
2021-04-16 15:51:26 +00:00
const remainingCount = sharedGroupNames.length - 3;
return (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:member-of-more-than-3-groups--multiple-more"
2021-04-16 15:51:26 +00:00
components={{
group1: firstThreeGroups[0],
group2: firstThreeGroups[1],
group3: firstThreeGroups[2],
2023-04-03 19:03:00 +00:00
remainingCount,
2021-04-16 15:51:26 +00:00
}}
/>
);
}
if (sharedGroupNames.length === 4) {
return (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:member-of-more-than-3-groups--one-more"
components={{
group1: firstThreeGroups[0],
group2: firstThreeGroups[1],
group3: firstThreeGroups[2],
}}
/>
);
}
2021-04-16 15:51:26 +00:00
if (firstThreeGroups.length === 3) {
return (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:member-of-3-groups"
2021-04-16 15:51:26 +00:00
components={{
group1: firstThreeGroups[0],
group2: firstThreeGroups[1],
group3: firstThreeGroups[2],
}}
/>
);
}
if (firstThreeGroups.length >= 2) {
return (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:member-of-2-groups"
2021-04-16 15:51:26 +00:00
components={{
group1: firstThreeGroups[0],
group2: firstThreeGroups[1],
}}
/>
);
}
if (firstThreeGroups.length >= 1) {
return (
<Intl
i18n={i18n}
2023-03-30 00:03:25 +00:00
id="icu:member-of-1-group"
2021-04-16 15:51:26 +00:00
components={{
group: firstThreeGroups[0],
}}
/>
);
}
2023-03-30 00:03:25 +00:00
return <>{i18n('icu:no-groups-in-common')}</>;
2022-11-18 00:45:19 +00:00
}