signal-desktop/ts/state/smart/ContactName.tsx

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
import React, { memo, useCallback, useMemo } from 'react';
2020-09-08 19:25:05 -07:00
import { useSelector } from 'react-redux';
import { ContactName } from '../../components/conversation/ContactName';
import { getIntl } from '../selectors/user';
import {
getConversationSelector,
getSelectedConversationId,
} from '../selectors/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
2020-09-08 19:25:05 -07:00
type ExternalProps = {
contactId: string;
2020-09-08 19:25:05 -07:00
};
export const SmartContactName = memo(function SmartContactName({
contactId,
}: ExternalProps) {
const i18n = useSelector(getIntl);
const getConversation = useSelector(getConversationSelector);
const currentConversationId = useSelector(getSelectedConversationId);
const { showContactModal } = useGlobalModalActions();
2020-09-08 19:25:05 -07:00
const contact = useMemo(() => {
return getConversation(contactId);
}, [getConversation, contactId]);
const handleClick = useCallback(() => {
showContactModal(contactId, currentConversationId);
}, [showContactModal, contactId, currentConversationId]);
2021-05-28 12:15:17 -04:00
return (
<ContactName
firstName={contact.firstName}
title={contact.title ?? i18n('icu:unknownContact')}
onClick={handleClick}
2021-05-28 12:15:17 -04:00
/>
);
});