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

74 lines
1.8 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 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;
2022-11-18 00:45:19 +00:00
export function UsernameSearchResultListItem({
2021-11-12 01:17:29 +00:00
i18n,
isFetchingUsername,
lookupConversationWithoutUuid,
2021-11-12 01:17:29 +00:00
username,
showUserNotFoundModal,
setIsFetchingUUID,
showConversation,
2022-11-18 00:45:19 +00:00
}: Props): JSX.Element {
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}
/>
);
2022-11-18 00:45:19 +00:00
}