signal-desktop/ts/components/conversationList/UsernameSearchResultListItem.tsx

75 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-11-12 01:17:29 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { FunctionComponent } from 'react';
import React, { useCallback } from 'react';
2021-11-12 01:17:29 +00:00
import { BaseConversationListItem } from './BaseConversationListItem';
import type { LocalizerType } from '../../types/Util';
import type { LookupConversationWithoutUuidActionsType } from '../../util/lookupConversationWithoutUuid';
2022-06-16 19:12:50 +00:00
import type { ShowConversationType } from '../../state/ducks/conversations';
2021-11-12 01:17:29 +00:00
type PropsData = {
username: string;
isFetchingUsername: boolean;
};
type PropsHousekeeping = {
i18n: LocalizerType;
2022-06-16 19:12:50 +00:00
showConversation: ShowConversationType;
} & LookupConversationWithoutUuidActionsType;
2021-11-12 01:17:29 +00:00
export type Props = PropsData & PropsHousekeeping;
export const UsernameSearchResultListItem: FunctionComponent<Props> = ({
i18n,
isFetchingUsername,
lookupConversationWithoutUuid,
2021-11-12 01:17:29 +00:00
username,
showUserNotFoundModal,
setIsFetchingUUID,
showConversation,
2021-11-12 01:17:29 +00:00
}) => {
const usernameText = i18n('at-username', { username });
const boundOnClick = useCallback(async () => {
if (isFetchingUsername) {
return;
}
const conversationId = await lookupConversationWithoutUuid({
showUserNotFoundModal,
setIsFetchingUUID,
type: 'username',
username,
});
if (conversationId !== undefined) {
2022-06-16 19:12:50 +00:00
showConversation({ conversationId });
}
}, [
isFetchingUsername,
lookupConversationWithoutUuid,
setIsFetchingUUID,
showConversation,
showUserNotFoundModal,
username,
]);
2021-11-12 01:17:29 +00:00
return (
<BaseConversationListItem
acceptedMessageRequest={false}
conversationType="direct"
headerName={usernameText}
i18n={i18n}
isMe={false}
isSelected={false}
isUsernameSearchResult
shouldShowSpinner={isFetchingUsername}
onClick={boundOnClick}
sharedGroupNames={[]}
title={usernameText}
/>
);
};