// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { ReactChild } from 'react'; import { LeftPaneHelper } from './LeftPaneHelper'; import { Row, RowType } from '../ConversationList'; import { PropsDataType as ContactListItemPropsType } from '../conversationList/ContactListItem'; import { LocalizerType } from '../../types/Util'; import { AvatarInput } from '../AvatarInput'; import { Alert } from '../Alert'; import { Spinner } from '../Spinner'; import { Button } from '../Button'; import { GroupTitleInput } from '../GroupTitleInput'; export type LeftPaneSetGroupMetadataPropsType = { groupAvatar: undefined | ArrayBuffer; groupName: string; hasError: boolean; isCreating: boolean; selectedContacts: ReadonlyArray; }; /* eslint-disable class-methods-use-this */ export class LeftPaneSetGroupMetadataHelper extends LeftPaneHelper< LeftPaneSetGroupMetadataPropsType > { private readonly groupAvatar: undefined | ArrayBuffer; private readonly groupName: string; private readonly hasError: boolean; private readonly isCreating: boolean; private readonly selectedContacts: ReadonlyArray; constructor({ groupAvatar, groupName, isCreating, hasError, selectedContacts, }: Readonly) { super(); this.groupAvatar = groupAvatar; this.groupName = groupName; this.hasError = hasError; this.isCreating = isCreating; this.selectedContacts = selectedContacts; } getHeaderContents({ i18n, showChooseGroupMembers, }: Readonly<{ i18n: LocalizerType; showChooseGroupMembers: () => void; }>): ReactChild { const backButtonLabel = i18n('setGroupMetadata__back-button'); return (
); } getPreRowsNode({ clearGroupCreationError, createGroup, i18n, setComposeGroupAvatar, setComposeGroupName, }: Readonly<{ clearGroupCreationError: () => unknown; createGroup: () => unknown; i18n: LocalizerType; setComposeGroupAvatar: (_: undefined | ArrayBuffer) => unknown; setComposeGroupName: (_: string) => unknown; }>): ReactChild { const disabled = this.isCreating; return (
{ event.preventDefault(); event.stopPropagation(); if (!this.canCreateGroup()) { return; } createGroup(); }} > {this.hasError && ( )} ); } getFooterContents({ createGroup, i18n, }: Readonly<{ createGroup: () => unknown; i18n: LocalizerType; }>): ReactChild { return ( ); } getRowCount(): number { if (!this.selectedContacts.length) { return 0; } return this.selectedContacts.length + 2; } getRow(rowIndex: number): undefined | Row { if (!this.selectedContacts.length) { return undefined; } if (rowIndex === 0) { return { type: RowType.Header, i18nKey: 'setGroupMetadata__members-header', }; } // This puts a blank row for the footer. if (rowIndex === this.selectedContacts.length + 1) { return { type: RowType.Blank }; } const contact = this.selectedContacts[rowIndex - 1]; return contact ? { type: RowType.Contact, contact, isClickable: false, } : undefined; } // This is deliberately unimplemented because these keyboard shortcuts shouldn't work in // the composer. The same is true for the "in direction" function below. getConversationAndMessageAtIndex( ..._args: ReadonlyArray ): undefined { return undefined; } getConversationAndMessageInDirection( ..._args: ReadonlyArray ): undefined { return undefined; } shouldRecomputeRowHeights(_old: unknown): boolean { return false; } private canCreateGroup(): boolean { return !this.isCreating && Boolean(this.groupName.trim()); } } function focusRef(el: HTMLElement | null) { if (el) { el.focus(); } }