import React, { useRef } from 'react'; import { Link } from 'react-router-dom'; import { Avatar, HStack, Icon, Stack, Text } from 'soapbox/components/ui'; import VerificationBadge from 'soapbox/components/verification_badge'; import { useChatContext } from 'soapbox/contexts/chat-context'; import Chat from '../chat'; import ChatPaneHeader from './chat-pane-header'; import ChatSettings from './chat-settings'; const LinkWrapper = ({ enabled, to, children }: { enabled: boolean, to: string, children: React.ReactNode }): JSX.Element => { if (!enabled) { return <>{children}; } return ( {children} ); }; /** Floating desktop chat window. */ const ChatWindow = () => { const { chat, setChat, isOpen, isEditing, needsAcceptance, setEditing, setSearching, toggleChatPane } = useChatContext(); const inputRef = useRef(); const closeChat = () => setChat(null); const openSearch = () => { toggleChatPane(); setSearching(true); setChat(null); }; const openChatSettings = () => setEditing(true); const secondaryAction = () => { if (needsAcceptance) { return undefined; } return isOpen ? openChatSettings : openSearch; }; if (!chat) return null; if (isEditing) { return ; } return ( <> {isOpen && ( )} {isOpen && ( )}
{chat.account.display_name} {chat.account.verified && }
@{chat.account.acct}
} secondaryAction={secondaryAction()} secondaryActionIcon={isOpen ? require('@tabler/icons/info-circle.svg') : require('@tabler/icons/edit.svg')} isToggleable={!isOpen} isOpen={isOpen} onToggle={toggleChatPane} /> ); }; export default ChatWindow;