// Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { useState } from 'react'; import classNames from 'classnames'; import type { ConversationType } from '../state/ducks/conversations'; import type { LocalizerType } from '../types/Util'; import type { MyStoryType, StoryViewType } from '../types/Stories'; import type { ShowToastActionCreatorType } from '../state/ducks/toast'; import { Avatar, AvatarSize } from './Avatar'; import { HasStories, ResolvedSendStatus } from '../types/Stories'; import { MessageTimestamp } from './conversation/MessageTimestamp'; import { StoriesAddStoryButton } from './StoriesAddStoryButton'; import { StoryImage } from './StoryImage'; import { getAvatarColor } from '../types/Colors'; import { reduceStorySendStatus } from '../util/resolveStorySendStatus'; export type PropsType = { i18n: LocalizerType; me: ConversationType; myStories: Array; onAddStory: () => unknown; onClick: () => unknown; queueStoryDownload: (storyId: string) => unknown; showToast: ShowToastActionCreatorType; }; function getNewestMyStory(story: MyStoryType): StoryViewType { return story.stories[0]; } export function MyStoryButton({ i18n, me, myStories, onAddStory, onClick, queueStoryDownload, showToast, }: PropsType): JSX.Element { const [active, setActive] = useState(false); const newestStory = myStories.length ? getNewestMyStory(myStories[0]) : undefined; const { acceptedMessageRequest, avatarPath, color, isMe, profileName, sharedGroupNames, title, } = me; if (!newestStory) { return (
{i18n('Stories__mine')}
{i18n('Stories__add')}
); } const hasMultiple = myStories.length ? myStories[0].stories.length > 1 : false; const reducedSendStatus: ResolvedSendStatus = myStories.reduce( (acc: ResolvedSendStatus, myStory) => reduceStorySendStatus(acc, myStory.reducedSendStatus), ResolvedSendStatus.Sent ); return (
{ if (ev.key === 'Enter') { onClick(); ev.stopPropagation(); ev.preventDefault(); } }} role="button" tabIndex={0} >
{i18n('MyStories__list_item')}
{reducedSendStatus === ResolvedSendStatus.Sending && ( {i18n('Stories__list--sending')} )} {reducedSendStatus === ResolvedSendStatus.Failed && ( {i18n('Stories__list--send_failed')} )} {reducedSendStatus === ResolvedSendStatus.PartiallySent && ( {i18n('Stories__list--partially-sent')} )} {reducedSendStatus === ResolvedSendStatus.Sent && ( )}
{hasMultiple &&
}
); }