/* * Wire * Copyright (C) 2024 Wire Swiss GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * */ import {forwardRef, KeyboardEvent, MutableRefObject, useEffect} from 'react'; import {amplify} from 'amplify'; import {CircleCloseIcon, IconButton, Input, SearchIcon} from '@wireapp/react-ui-kit'; import {WebAppEvents} from '@wireapp/webapp-events'; import * as Icon from 'Components/Icon'; import {ConversationLabel} from 'src/script/conversation/ConversationLabelRepository'; import {SidebarTabs} from 'src/script/page/LeftSidebar/panels/Conversations/useSidebarStore'; import {handleEnterDown, handleEscDown} from 'Util/KeyboardUtil'; import {t} from 'Util/LocalizerUtil'; import { button, header, label, closeIconStyles, searchIconStyles, searchInputStyles, searchInputWrapperStyles, } from './ConversationHeader.styles'; import {User} from '../../../../../entity/User'; import {generatePermissionHelpers} from '../../../../../user/UserPermission'; interface ConversationHeaderProps { currentTab: SidebarTabs; selfUser: User; showSearchInput?: boolean; searchValue?: string; setSearchValue: (searchValue: string) => void; searchInputPlaceholder: string; currentFolder?: ConversationLabel; onSearchEnterClick: (event: KeyboardEvent) => void; jumpToRecentSearch: () => void; searchInputRef: MutableRefObject; } export const ConversationHeaderComponent = ({ currentTab, selfUser, showSearchInput = false, searchValue = '', setSearchValue, currentFolder, searchInputPlaceholder, onSearchEnterClick, jumpToRecentSearch, searchInputRef, }: ConversationHeaderProps) => { const {canCreateGroupConversation} = generatePermissionHelpers(selfUser.teamRole()); const isFolderView = currentTab === SidebarTabs.FOLDER; const conversationsHeaderTitle: Partial> = { [SidebarTabs.RECENT]: t('conversationViewAllConversations'), [SidebarTabs.FAVORITES]: t('conversationLabelFavorites'), [SidebarTabs.GROUPS]: t('conversationLabelGroups'), [SidebarTabs.DIRECTS]: t('conversationLabelDirects'), [SidebarTabs.FOLDER]: t('folderViewTooltip'), [SidebarTabs.ARCHIVES]: t('conversationFooterArchive'), [SidebarTabs.CONNECT]: t('searchConnect'), }; const onKeyDown = (event: KeyboardEvent) => { handleEscDown(event, () => setSearchValue('')); handleEnterDown(event, () => onSearchEnterClick(event)); }; useEffect(() => { const onSearchShortcut = () => { jumpToRecentSearch(); searchInputRef?.current?.focus(); }; amplify.subscribe(WebAppEvents.SHORTCUT.SEARCH, onSearchShortcut); return () => { amplify.unsubscribe(WebAppEvents.SHORTCUT.SEARCH, onSearchShortcut); }; }, [searchInputRef, jumpToRecentSearch]); return ( <>

{isFolderView && currentFolder ? currentFolder.name : conversationsHeaderTitle[currentTab]}

{currentTab !== SidebarTabs.ARCHIVES && canCreateGroupConversation() && ( amplify.publish(WebAppEvents.CONVERSATION.CREATE_GROUP, 'conversation_details')} data-uie-name="go-create-group" css={button} title={t('conversationDetailsActionCreateGroup')} > )}
{showSearchInput && ( setSearchValue(event.currentTarget.value)} startContent={} endContent={ searchValue && ( setSearchValue('')} css={closeIconStyles} /> ) } inputCSS={searchInputStyles} wrapperCSS={searchInputWrapperStyles} placeholder={searchInputPlaceholder} data-uie-name="search-conversations" /> )} ); }; export const ConversationHeader = forwardRef(ConversationHeaderComponent);