signal-desktop/ts/components/SendStoryModal.tsx

848 lines
28 KiB
TypeScript
Raw Normal View History

2022-08-02 19:31:55 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
2022-08-10 18:37:19 +00:00
import React, { useEffect, useMemo, useState } from 'react';
2022-08-30 19:13:32 +00:00
import { noop } from 'lodash';
2022-08-10 18:37:19 +00:00
import { SearchInput } from './SearchInput';
import { filterAndSortConversationsByRecent } from '../util/filterAndSortConversations';
2022-08-02 19:31:55 +00:00
import type { ConversationType } from '../state/ducks/conversations';
import type { LocalizerType } from '../types/Util';
2022-08-10 18:37:19 +00:00
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
2022-08-23 17:24:55 +00:00
import type { PropsType as StoriesSettingsModalPropsType } from './StoriesSettingsModal';
2022-08-30 19:13:32 +00:00
import type { StoryDistributionListWithMembersDataType } from '../types/Stories';
2022-08-02 19:31:55 +00:00
import type { UUIDStringType } from '../types/UUID';
import { Avatar, AvatarSize } from './Avatar';
2022-08-23 17:24:55 +00:00
import { Button, ButtonVariant } from './Button';
2022-08-02 19:31:55 +00:00
import { Checkbox } from './Checkbox';
2022-08-30 19:13:32 +00:00
import { ConfirmationDialog } from './ConfirmationDialog';
2022-08-10 18:37:19 +00:00
import { ContextMenu } from './ContextMenu';
import {
2022-08-30 19:13:32 +00:00
DistributionListSettings,
2022-08-10 18:37:19 +00:00
EditDistributionList,
2022-08-23 17:24:55 +00:00
EditMyStoriesPrivacy,
2022-08-10 18:37:19 +00:00
Page as StoriesSettingsPage,
} from './StoriesSettingsModal';
2022-08-02 19:31:55 +00:00
import { MY_STORIES_ID, getStoryDistributionListName } from '../types/Stories';
import { Modal } from './Modal';
import { StoryDistributionListName } from './StoryDistributionListName';
2022-08-10 18:37:19 +00:00
import { Theme } from '../util/theme';
import { isNotNil } from '../util/isNotNil';
2022-08-02 19:31:55 +00:00
export type PropsType = {
2022-08-10 18:37:19 +00:00
candidateConversations: Array<ConversationType>;
2022-08-30 19:13:32 +00:00
distributionLists: Array<StoryDistributionListWithMembersDataType>;
2022-08-10 18:37:19 +00:00
getPreferredBadge: PreferredBadgeSelectorType;
groupConversations: Array<ConversationType>;
groupStories: Array<ConversationType>;
2022-08-23 17:24:55 +00:00
hasFirstStoryPostExperience: boolean;
2022-08-02 19:31:55 +00:00
i18n: LocalizerType;
me: ConversationType;
onClose: () => unknown;
2022-08-30 19:13:32 +00:00
onDeleteList: (listId: string) => unknown;
2022-08-10 18:37:19 +00:00
onDistributionListCreated: (
name: string,
viewerUuids: Array<UUIDStringType>
) => unknown;
onSelectedStoryList: (memberUuids: Array<string>) => unknown;
2022-08-10 18:37:19 +00:00
onSend: (
listIds: Array<UUIDStringType>,
conversationIds: Array<string>
) => unknown;
2022-08-02 19:31:55 +00:00
signalConnections: Array<ConversationType>;
2022-08-30 19:13:32 +00:00
toggleGroupsForStorySend: (cids: Array<string>) => unknown;
2022-08-23 17:24:55 +00:00
} & Pick<
StoriesSettingsModalPropsType,
| 'onHideMyStoriesFrom'
2022-08-30 19:13:32 +00:00
| 'onRemoveMember'
| 'onRepliesNReactionsChanged'
2022-08-23 17:24:55 +00:00
| 'onViewersUpdated'
| 'setMyStoriesToAllSignalConnections'
| 'toggleSignalConnectionsModal'
>;
2022-08-10 18:37:19 +00:00
enum SendStoryPage {
ChooseGroups = 'ChooseGroups',
2022-08-30 19:13:32 +00:00
EditingDistributionList = 'EditingDistributionList',
2022-08-23 17:24:55 +00:00
SendStory = 'SendStory',
SetMyStoriesPrivacy = 'SetMyStoriesPrivacy',
2022-08-10 18:37:19 +00:00
}
const Page = {
...SendStoryPage,
...StoriesSettingsPage,
2022-08-02 19:31:55 +00:00
};
2022-08-10 18:37:19 +00:00
type PageType = SendStoryPage | StoriesSettingsPage;
function getListMemberUuids(
2022-08-30 19:13:32 +00:00
list: StoryDistributionListWithMembersDataType,
signalConnections: Array<ConversationType>
): Array<string> {
2022-08-30 19:13:32 +00:00
const memberUuids = list.members.map(({ uuid }) => uuid).filter(isNotNil);
if (list.id === MY_STORIES_ID && list.isBlockList) {
2022-08-30 19:13:32 +00:00
const excludeUuids = new Set<string>(memberUuids);
return signalConnections
.map(conversation => conversation.uuid)
.filter(isNotNil)
.filter(uuid => !excludeUuids.has(uuid));
}
2022-08-30 19:13:32 +00:00
return memberUuids;
}
2022-08-02 19:31:55 +00:00
function getListViewers(
2022-08-30 19:13:32 +00:00
list: StoryDistributionListWithMembersDataType,
2022-08-02 19:31:55 +00:00
i18n: LocalizerType,
signalConnections: Array<ConversationType>
): string {
2022-08-30 19:13:32 +00:00
let memberCount = list.members.length;
2022-08-02 19:31:55 +00:00
if (list.id === MY_STORIES_ID && list.isBlockList) {
memberCount = list.isBlockList
2022-08-30 19:13:32 +00:00
? signalConnections.length - list.members.length
2022-08-02 19:31:55 +00:00
: signalConnections.length;
}
return memberCount === 1
2022-08-10 18:37:19 +00:00
? i18n('StoriesSettings__viewers--singular', ['1'])
2022-08-02 19:31:55 +00:00
: i18n('StoriesSettings__viewers--plural', [String(memberCount)]);
}
export const SendStoryModal = ({
2022-08-10 18:37:19 +00:00
candidateConversations,
2022-08-02 19:31:55 +00:00
distributionLists,
2022-08-10 18:37:19 +00:00
getPreferredBadge,
groupConversations,
groupStories,
2022-08-23 17:24:55 +00:00
hasFirstStoryPostExperience,
2022-08-02 19:31:55 +00:00
i18n,
me,
onClose,
2022-08-30 19:13:32 +00:00
onDeleteList,
2022-08-10 18:37:19 +00:00
onDistributionListCreated,
2022-08-23 17:24:55 +00:00
onHideMyStoriesFrom,
2022-08-30 19:13:32 +00:00
onRemoveMember,
onRepliesNReactionsChanged,
onSelectedStoryList,
2022-08-30 19:13:32 +00:00
onSend,
2022-08-23 17:24:55 +00:00
onViewersUpdated,
setMyStoriesToAllSignalConnections,
2022-08-02 19:31:55 +00:00
signalConnections,
2022-08-30 19:13:32 +00:00
toggleGroupsForStorySend,
2022-08-23 17:24:55 +00:00
toggleSignalConnectionsModal,
2022-08-02 19:31:55 +00:00
}: PropsType): JSX.Element => {
2022-08-10 18:37:19 +00:00
const [page, setPage] = useState<PageType>(Page.SendStory);
2022-08-02 19:31:55 +00:00
const [selectedListIds, setSelectedListIds] = useState<Set<UUIDStringType>>(
new Set()
);
2022-08-10 18:37:19 +00:00
const [selectedGroupIds, setSelectedGroupIds] = useState<Set<string>>(
new Set()
);
const selectedStoryNames = useMemo(
2022-08-02 19:31:55 +00:00
() =>
distributionLists
.filter(list => selectedListIds.has(list.id))
2022-08-10 18:37:19 +00:00
.map(list => list.name)
.concat(
groupStories
.filter(group => selectedGroupIds.has(group.id))
.map(group => group.title)
),
[distributionLists, groupStories, selectedGroupIds, selectedListIds]
2022-08-02 19:31:55 +00:00
);
2022-08-10 18:37:19 +00:00
const [searchTerm, setSearchTerm] = useState('');
const [filteredConversations, setFilteredConversations] = useState(
filterAndSortConversationsByRecent(
groupConversations,
searchTerm,
undefined
)
);
const normalizedSearchTerm = searchTerm.trim();
useEffect(() => {
const timeout = setTimeout(() => {
setFilteredConversations(
filterAndSortConversationsByRecent(
groupConversations,
normalizedSearchTerm,
undefined
)
);
}, 200);
return () => {
clearTimeout(timeout);
};
}, [groupConversations, normalizedSearchTerm, setFilteredConversations]);
const [chosenGroupIds, setChosenGroupIds] = useState<Set<string>>(
new Set<string>()
);
const chosenGroupNames = useMemo(
() =>
filteredConversations
.filter(group => chosenGroupIds.has(group.id))
.map(group => group.title),
[filteredConversations, chosenGroupIds]
);
const [selectedContacts, setSelectedContacts] = useState<
Array<ConversationType>
>([]);
2022-08-30 19:13:32 +00:00
const [confirmRemoveGroupId, setConfirmRemoveGroupId] = useState<
string | undefined
>();
const [confirmDeleteListId, setConfirmDeleteListId] = useState<
string | undefined
>();
const [listIdToEdit, setListIdToEdit] = useState<string | undefined>();
useEffect(() => {
if (listIdToEdit) {
setPage(Page.EditingDistributionList);
} else {
setPage(Page.SendStory);
}
}, [listIdToEdit]);
const listToEdit = useMemo(() => {
if (!listIdToEdit) {
return;
}
return distributionLists.find(list => list.id === listIdToEdit);
}, [distributionLists, listIdToEdit]);
// myStoriesPrivacy, myStoriesPrivacyUuids, and myStories are only used
// during the first time posting to My Stories experience where we have
// to select the privacy settings.
const ogMyStories = useMemo(
() => distributionLists.find(list => list.id === MY_STORIES_ID),
[distributionLists]
2022-08-23 17:24:55 +00:00
);
2022-08-30 19:13:32 +00:00
const initialMyStories = useMemo(
() => ({
2022-08-23 17:24:55 +00:00
allowsReplies: true,
id: MY_STORIES_ID,
2022-08-30 19:13:32 +00:00
name: i18n('Stories__mine'),
isBlockList: ogMyStories?.isBlockList ?? true,
members: ogMyStories?.members || [],
}),
[i18n, ogMyStories]
);
const initialMyStoriesMemberUuids = useMemo(
() => (ogMyStories?.members || []).map(({ uuid }) => uuid).filter(isNotNil),
[ogMyStories]
);
const [stagedMyStories, setStagedMyStories] =
useState<StoryDistributionListWithMembersDataType>(initialMyStories);
const [stagedMyStoriesMemberUuids, setStagedMyStoriesMemberUuids] = useState<
Array<UUIDStringType>
>(initialMyStoriesMemberUuids);
2022-08-23 17:24:55 +00:00
2022-08-10 18:37:19 +00:00
let content: JSX.Element;
2022-08-23 17:24:55 +00:00
if (page === Page.SetMyStoriesPrivacy) {
content = (
<EditMyStoriesPrivacy
hasDisclaimerAbove
i18n={i18n}
learnMore="SendStoryModal__privacy-disclaimer"
2022-08-30 19:13:32 +00:00
myStories={stagedMyStories}
2022-08-23 17:24:55 +00:00
onClickExclude={() => {
2022-08-30 19:13:32 +00:00
let nextSelectedContacts = stagedMyStories.members;
if (!stagedMyStories.isBlockList) {
setStagedMyStories(myStories => ({
...myStories,
isBlockList: true,
members: [],
}));
nextSelectedContacts = [];
}
setSelectedContacts(nextSelectedContacts);
2022-08-23 17:24:55 +00:00
setPage(Page.HideStoryFrom);
}}
onClickOnlyShareWith={() => {
2022-08-30 19:13:32 +00:00
if (!stagedMyStories.isBlockList) {
setSelectedContacts(stagedMyStories.members);
} else {
setStagedMyStories(myStories => ({
...myStories,
isBlockList: false,
members: [],
}));
}
2022-08-23 17:24:55 +00:00
setPage(Page.AddViewer);
}}
setSelectedContacts={setSelectedContacts}
setMyStoriesToAllSignalConnections={() => {
2022-08-30 19:13:32 +00:00
setStagedMyStories(myStories => ({
...myStories,
isBlockList: true,
members: [],
}));
2022-08-23 17:24:55 +00:00
setSelectedContacts([]);
}}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
/>
);
2022-08-30 19:13:32 +00:00
} else if (page === Page.EditingDistributionList && listToEdit) {
content = (
<DistributionListSettings
getPreferredBadge={getPreferredBadge}
i18n={i18n}
listToEdit={listToEdit}
onRemoveMember={onRemoveMember}
onRepliesNReactionsChanged={onRepliesNReactionsChanged}
setConfirmDeleteListId={setConfirmDeleteListId}
setMyStoriesToAllSignalConnections={setMyStoriesToAllSignalConnections}
setPage={setPage}
setSelectedContacts={setSelectedContacts}
toggleSignalConnectionsModal={toggleSignalConnectionsModal}
/>
);
2022-08-23 17:24:55 +00:00
} else if (
page === Page.ChooseViewers ||
page === Page.NameStory ||
page === Page.AddViewer ||
page === Page.HideStoryFrom
) {
2022-08-10 18:37:19 +00:00
content = (
<EditDistributionList
candidateConversations={candidateConversations}
getPreferredBadge={getPreferredBadge}
i18n={i18n}
2022-08-30 19:13:32 +00:00
onCreateList={(name, uuids) => {
2022-08-10 18:37:19 +00:00
onDistributionListCreated(name, uuids);
setPage(Page.SendStory);
}}
2022-08-23 17:24:55 +00:00
onViewersUpdated={uuids => {
2022-08-30 19:13:32 +00:00
if (listIdToEdit && page === Page.AddViewer) {
onViewersUpdated(listIdToEdit, uuids);
setPage(Page.EditingDistributionList);
} else if (page === Page.ChooseViewers) {
2022-08-10 18:37:19 +00:00
setPage(Page.NameStory);
2022-08-30 19:13:32 +00:00
} else if (listIdToEdit && page === Page.HideStoryFrom) {
onHideMyStoriesFrom(uuids);
setPage(Page.SendStory);
2022-08-23 17:24:55 +00:00
} else if (page === Page.HideStoryFrom || page === Page.AddViewer) {
2022-08-30 19:13:32 +00:00
setStagedMyStoriesMemberUuids(uuids);
2022-08-23 17:24:55 +00:00
setPage(Page.SetMyStoriesPrivacy);
2022-08-10 18:37:19 +00:00
} else {
setPage(Page.SendStory);
}
}}
page={page}
selectedContacts={selectedContacts}
setSelectedContacts={setSelectedContacts}
/>
);
} else if (page === Page.ChooseGroups) {
content = (
<>
<SearchInput
disabled={groupConversations.length === 0}
i18n={i18n}
placeholder={i18n('contactSearchPlaceholder')}
moduleClassName="StoriesSettingsModal__search"
onChange={event => {
setSearchTerm(event.target.value);
}}
value={searchTerm}
/>
{filteredConversations.length ? (
filteredConversations.map(group => (
<Checkbox
checked={chosenGroupIds.has(group.id)}
key={group.id}
label={group.title}
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
setChosenGroupIds(groupIds => {
if (value) {
groupIds.add(group.id);
} else {
groupIds.delete(group.id);
}
return new Set([...groupIds]);
});
}}
>
{({ id, checkboxNode }) => (
<>
<label
className="SendStoryModal__distribution-list__label"
htmlFor={id}
>
<Avatar
acceptedMessageRequest={group.acceptedMessageRequest}
avatarPath={group.avatarPath}
badge={undefined}
color={group.color}
conversationType={group.type}
i18n={i18n}
isMe={false}
sharedGroupNames={[]}
size={AvatarSize.THIRTY_SIX}
title={group.title}
/>
<div className="SendStoryModal__distribution-list__info">
<div className="SendStoryModal__distribution-list__name">
{group.title}
</div>
<div className="SendStoryModal__distribution-list__description">
{group.membersCount === 1
? i18n('ConversationHero--members-1')
: i18n('ConversationHero--members', [
String(group.membersCount),
])}
</div>
</div>
</label>
{checkboxNode}
</>
)}
</Checkbox>
))
) : (
<div className="module-ForwardMessageModal__no-candidate-contacts">
{i18n('noContactsFound')}
</div>
)}
</>
);
} else {
content = (
<>
<div className="SendStoryModal__top-bar">
{i18n('stories')}
<ContextMenu
aria-label={i18n('SendStoryModal__new')}
i18n={i18n}
menuOptions={[
{
label: i18n('SendStoryModal__new-private--title'),
description: i18n('SendStoryModal__new-private--description'),
icon: 'SendStoryModal__icon--lock',
onClick: () => setPage(Page.ChooseViewers),
},
{
label: i18n('SendStoryModal__new-group--title'),
description: i18n('SendStoryModal__new-group--description'),
icon: 'SendStoryModal__icon--group',
onClick: () => setPage(Page.ChooseGroups),
},
]}
moduleClassName="SendStoryModal__new-story"
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
theme={Theme.Dark}
>
{i18n('SendStoryModal__new')}
</ContextMenu>
</div>
{distributionLists.map(list => (
<Checkbox
checked={selectedListIds.has(list.id)}
key={list.id}
label={getStoryDistributionListName(i18n, list.id, list.name)}
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
2022-08-23 17:24:55 +00:00
if (
list.id === MY_STORIES_ID &&
hasFirstStoryPostExperience &&
value
) {
setPage(Page.SetMyStoriesPrivacy);
return;
}
2022-08-02 19:31:55 +00:00
setSelectedListIds(listIds => {
2022-08-10 18:37:19 +00:00
if (value) {
listIds.add(list.id);
} else {
listIds.delete(list.id);
}
2022-08-02 19:31:55 +00:00
return new Set([...listIds]);
});
if (value) {
onSelectedStoryList(
getListMemberUuids(list, signalConnections)
);
}
2022-08-10 18:37:19 +00:00
}}
>
{({ id, checkboxNode }) => (
2022-08-30 19:13:32 +00:00
<ContextMenu
i18n={i18n}
menuOptions={
list.id === MY_STORIES_ID
? [
{
label: i18n('StoriesSettings__context-menu'),
icon: 'SendStoryModal__icon--delete',
onClick: () => setListIdToEdit(list.id),
},
]
: [
{
label: i18n('StoriesSettings__context-menu'),
icon: 'SendStoryModal__icon--settings',
onClick: () => setListIdToEdit(list.id),
},
{
label: i18n('SendStoryModal__delete-story'),
icon: 'SendStoryModal__icon--delete',
onClick: () => setConfirmDeleteListId(list.id),
},
]
}
moduleClassName="SendStoryModal__distribution-list-context"
onClick={noop}
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
theme={Theme.Dark}
>
2022-08-10 18:37:19 +00:00
<label
className="SendStoryModal__distribution-list__label"
htmlFor={id}
>
{list.id === MY_STORIES_ID ? (
<Avatar
acceptedMessageRequest={me.acceptedMessageRequest}
avatarPath={me.avatarPath}
badge={undefined}
color={me.color}
conversationType={me.type}
i18n={i18n}
isMe
sharedGroupNames={me.sharedGroupNames}
size={AvatarSize.THIRTY_SIX}
title={me.title}
/>
) : (
<span className="StoriesSettingsModal__list__avatar--private" />
)}
<div className="SendStoryModal__distribution-list__info">
<div className="SendStoryModal__distribution-list__name">
<StoryDistributionListName
i18n={i18n}
id={list.id}
name={list.name}
/>
</div>
<div className="SendStoryModal__distribution-list__description">
2022-08-23 17:24:55 +00:00
{hasFirstStoryPostExperience && list.id === MY_STORIES_ID
? i18n('SendStoryModal__choose-who-can-view')
: getListViewers(list, i18n, signalConnections)}
2022-08-10 18:37:19 +00:00
</div>
</div>
</label>
{checkboxNode}
2022-08-30 19:13:32 +00:00
</ContextMenu>
2022-08-10 18:37:19 +00:00
)}
</Checkbox>
))}
{groupStories.map(group => (
<Checkbox
checked={selectedGroupIds.has(group.id)}
key={group.id}
label={group.title}
moduleClassName="SendStoryModal__distribution-list"
name="SendStoryModal__distribution-list"
onChange={(value: boolean) => {
if (!group.memberships) {
return;
}
2022-08-10 18:37:19 +00:00
setSelectedGroupIds(groupIds => {
if (value) {
groupIds.add(group.id);
} else {
groupIds.delete(group.id);
}
return new Set([...groupIds]);
2022-08-02 19:31:55 +00:00
});
if (value) {
onSelectedStoryList(group.memberships.map(({ uuid }) => uuid));
}
2022-08-10 18:37:19 +00:00
}}
>
{({ id, checkboxNode }) => (
2022-08-30 19:13:32 +00:00
<ContextMenu
i18n={i18n}
menuOptions={[
{
label: i18n('SendStoryModal__delete-story'),
icon: 'SendStoryModal__icon--delete',
onClick: () => setConfirmRemoveGroupId(group.id),
},
]}
moduleClassName="SendStoryModal__distribution-list-context"
onClick={noop}
popperOptions={{
placement: 'bottom',
strategy: 'absolute',
}}
theme={Theme.Dark}
>
2022-08-10 18:37:19 +00:00
<label
className="SendStoryModal__distribution-list__label"
htmlFor={id}
>
2022-08-02 19:31:55 +00:00
<Avatar
2022-08-10 18:37:19 +00:00
acceptedMessageRequest={group.acceptedMessageRequest}
avatarPath={group.avatarPath}
2022-08-02 19:31:55 +00:00
badge={undefined}
2022-08-10 18:37:19 +00:00
color={group.color}
conversationType={group.type}
2022-08-02 19:31:55 +00:00
i18n={i18n}
2022-08-10 18:37:19 +00:00
isMe={false}
sharedGroupNames={[]}
2022-08-02 19:31:55 +00:00
size={AvatarSize.THIRTY_SIX}
2022-08-10 18:37:19 +00:00
title={group.title}
2022-08-02 19:31:55 +00:00
/>
2022-08-10 18:37:19 +00:00
<div className="SendStoryModal__distribution-list__info">
<div className="SendStoryModal__distribution-list__name">
{group.title}
</div>
2022-08-02 19:31:55 +00:00
2022-08-10 18:37:19 +00:00
<div className="SendStoryModal__distribution-list__description">
{group.membersCount === 1
? i18n('ConversationHero--members-1')
: i18n('ConversationHero--members', [
String(group.membersCount),
])}
</div>
2022-08-02 19:31:55 +00:00
</div>
2022-08-10 18:37:19 +00:00
</label>
{checkboxNode}
2022-08-30 19:13:32 +00:00
</ContextMenu>
2022-08-10 18:37:19 +00:00
)}
</Checkbox>
))}
</>
);
}
let modalTitle: string;
2022-08-23 17:24:55 +00:00
if (page === Page.SetMyStoriesPrivacy) {
modalTitle = i18n('SendStoryModal__my-stories-privacy');
} else if (page === Page.HideStoryFrom) {
modalTitle = i18n('StoriesSettings__hide-story');
} else if (page === Page.ChooseGroups) {
2022-08-10 18:37:19 +00:00
modalTitle = i18n('SendStoryModal__choose-groups');
} else if (page === Page.NameStory) {
modalTitle = i18n('StoriesSettings__name-story');
2022-08-23 17:24:55 +00:00
} else if (page === Page.ChooseViewers || page === Page.AddViewer) {
2022-08-10 18:37:19 +00:00
modalTitle = i18n('StoriesSettings__choose-viewers');
} else {
modalTitle = i18n('SendStoryModal__title');
}
2022-08-02 19:31:55 +00:00
2022-08-10 18:37:19 +00:00
let selectedNames: string | undefined;
if (page === Page.ChooseGroups) {
selectedNames = chosenGroupNames.join(', ');
} else {
selectedNames = selectedStoryNames
.map(listName => getStoryDistributionListName(i18n, listName, listName))
.join(', ');
}
const hasBackButton = page !== Page.SendStory;
let modalFooter: JSX.Element | undefined;
2022-08-23 17:24:55 +00:00
if (
page === Page.SendStory ||
page === Page.ChooseGroups ||
page === Page.SetMyStoriesPrivacy
) {
2022-08-10 18:37:19 +00:00
modalFooter = (
2022-08-02 19:31:55 +00:00
<Modal.ButtonFooter moduleClassName="SendStoryModal">
2022-08-23 17:24:55 +00:00
{page !== Page.SetMyStoriesPrivacy && (
<div className="SendStoryModal__selected-lists">{selectedNames}</div>
)}
2022-08-10 18:37:19 +00:00
{page === Page.ChooseGroups && (
<button
aria-label="SendStoryModal__ok"
className="SendStoryModal__ok"
disabled={!chosenGroupIds.size}
onClick={() => {
2022-08-30 19:13:32 +00:00
toggleGroupsForStorySend(Array.from(chosenGroupIds));
2022-08-10 18:37:19 +00:00
setChosenGroupIds(new Set());
setPage(Page.SendStory);
}}
type="button"
/>
)}
{page === Page.SendStory && (
<button
aria-label="SendStoryModal__send"
className="SendStoryModal__send"
disabled={!selectedListIds.size && !selectedGroupIds.size}
onClick={() => {
onSend(Array.from(selectedListIds), Array.from(selectedGroupIds));
}}
type="button"
/>
)}
2022-08-23 17:24:55 +00:00
{page === Page.SetMyStoriesPrivacy && (
<>
<div />
<div>
<Button
onClick={() => setPage(Page.SendStory)}
variant={ButtonVariant.Secondary}
>
{i18n('cancel')}
</Button>
<Button
onClick={() => {
2022-08-30 19:13:32 +00:00
if (stagedMyStories.isBlockList) {
if (stagedMyStories.members.length) {
onHideMyStoriesFrom(stagedMyStoriesMemberUuids);
} else {
setMyStoriesToAllSignalConnections();
}
} else {
onViewersUpdated(MY_STORIES_ID, stagedMyStoriesMemberUuids);
2022-08-23 17:24:55 +00:00
}
2022-08-30 19:13:32 +00:00
2022-08-23 17:24:55 +00:00
setSelectedContacts([]);
setPage(Page.SendStory);
}}
variant={ButtonVariant.Primary}
>
{i18n('save')}
</Button>
</div>
</>
)}
2022-08-02 19:31:55 +00:00
</Modal.ButtonFooter>
2022-08-10 18:37:19 +00:00
);
}
return (
2022-08-30 19:13:32 +00:00
<>
<Modal
hasStickyButtons
hasXButton
i18n={i18n}
modalFooter={modalFooter}
onBackButtonClick={
hasBackButton
? () => {
if (listIdToEdit) {
if (
page === Page.AddViewer ||
page === Page.HideStoryFrom ||
page === Page.ChooseViewers
) {
setPage(Page.EditingDistributionList);
} else {
setListIdToEdit(undefined);
}
} else if (page === Page.SetMyStoriesPrivacy) {
setSelectedContacts([]);
setStagedMyStories(initialMyStories);
setStagedMyStoriesMemberUuids(initialMyStoriesMemberUuids);
setPage(Page.SendStory);
} else if (
page === Page.HideStoryFrom ||
page === Page.AddViewer
) {
setSelectedContacts([]);
setStagedMyStories(initialMyStories);
setStagedMyStoriesMemberUuids(initialMyStoriesMemberUuids);
setPage(Page.SetMyStoriesPrivacy);
} else if (page === Page.ChooseGroups) {
setChosenGroupIds(new Set());
setPage(Page.SendStory);
} else if (page === Page.ChooseViewers) {
setSelectedContacts([]);
setPage(Page.SendStory);
} else if (page === Page.NameStory) {
setPage(Page.ChooseViewers);
}
2022-08-10 18:37:19 +00:00
}
2022-08-30 19:13:32 +00:00
: undefined
}
onClose={onClose}
title={modalTitle}
theme={Theme.Dark}
>
{content}
</Modal>
{confirmRemoveGroupId && (
<ConfirmationDialog
actions={[
{
action: () => {
toggleGroupsForStorySend([confirmRemoveGroupId]);
setConfirmRemoveGroupId(undefined);
},
style: 'negative',
text: i18n('delete'),
},
]}
i18n={i18n}
onClose={() => {
setConfirmRemoveGroupId(undefined);
}}
>
{i18n('SendStoryModal__confirm-remove-group')}
</ConfirmationDialog>
)}
{confirmDeleteListId && (
<ConfirmationDialog
actions={[
{
action: () => {
onDeleteList(confirmDeleteListId);
setConfirmDeleteListId(undefined);
// setListToEditId(undefined);
},
style: 'negative',
text: i18n('delete'),
},
]}
i18n={i18n}
onClose={() => {
setConfirmDeleteListId(undefined);
}}
>
{i18n('StoriesSettings__delete-list--confirm')}
</ConfirmationDialog>
)}
</>
2022-08-02 19:31:55 +00:00
);
};