2021-04-16 15:51:26 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import React from 'react';
|
2021-04-16 15:51:26 +00:00
|
|
|
import { take } from 'lodash';
|
|
|
|
|
2024-05-15 21:48:02 +00:00
|
|
|
import { I18n } from './I18n';
|
2021-10-26 19:15:33 +00:00
|
|
|
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;
|
2022-12-22 00:07:02 +00:00
|
|
|
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>
|
|
|
|
));
|
|
|
|
|
2021-09-17 20:57:54 +00:00
|
|
|
if (sharedGroupNames.length >= 5) {
|
2021-04-16 15:51:26 +00:00
|
|
|
const remainingCount = sharedGroupNames.length - 3;
|
|
|
|
return (
|
2024-05-15 21:48:02 +00:00
|
|
|
<I18n
|
2021-04-16 15:51:26 +00:00
|
|
|
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
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-09-17 20:57:54 +00:00
|
|
|
if (sharedGroupNames.length === 4) {
|
|
|
|
return (
|
2024-05-15 21:48:02 +00:00
|
|
|
<I18n
|
2021-09-17 20:57:54 +00:00
|
|
|
i18n={i18n}
|
2023-03-30 00:03:25 +00:00
|
|
|
id="icu:member-of-more-than-3-groups--one-more"
|
2021-09-17 20:57:54 +00:00
|
|
|
components={{
|
|
|
|
group1: firstThreeGroups[0],
|
|
|
|
group2: firstThreeGroups[1],
|
|
|
|
group3: firstThreeGroups[2],
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2021-04-16 15:51:26 +00:00
|
|
|
if (firstThreeGroups.length === 3) {
|
|
|
|
return (
|
2024-05-15 21:48:02 +00:00
|
|
|
<I18n
|
2021-04-16 15:51:26 +00:00
|
|
|
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 (
|
2024-05-15 21:48:02 +00:00
|
|
|
<I18n
|
2021-04-16 15:51:26 +00:00
|
|
|
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 (
|
2024-05-15 21:48:02 +00:00
|
|
|
<I18n
|
2021-04-16 15:51:26 +00:00
|
|
|
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
|
|
|
}
|