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

90 lines
2.2 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
2023-03-08 23:41:32 +00:00
import { SPINNER_CLASS_NAME } from './BaseConversationListItem';
import { ListTile } from '../ListTile';
import { Avatar, AvatarSize } from '../Avatar';
import { Spinner } from '../Spinner';
2021-11-12 01:17:29 +00:00
import type { LocalizerType } from '../../types/Util';
import type { LookupConversationWithoutServiceIdActionsType } from '../../util/lookupConversationWithoutServiceId';
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;
} & LookupConversationWithoutServiceIdActionsType;
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,
lookupConversationWithoutServiceId,
2021-11-12 01:17:29 +00:00
username,
showUserNotFoundModal,
setIsFetchingUUID,
showConversation,
2022-11-18 00:45:19 +00:00
}: Props): JSX.Element {
const boundOnClick = useCallback(async () => {
if (isFetchingUsername) {
return;
}
const conversationId = await lookupConversationWithoutServiceId({
showUserNotFoundModal,
setIsFetchingUUID,
type: 'username',
username,
});
if (conversationId !== undefined) {
2022-06-16 19:12:50 +00:00
showConversation({ conversationId });
}
}, [
isFetchingUsername,
lookupConversationWithoutServiceId,
setIsFetchingUUID,
showConversation,
showUserNotFoundModal,
username,
]);
2021-11-12 01:17:29 +00:00
return (
2023-03-08 23:41:32 +00:00
<ListTile
leading={
<Avatar
acceptedMessageRequest={false}
conversationType="direct"
searchResult
i18n={i18n}
isMe={false}
title={username}
size={AvatarSize.THIRTY_TWO}
badge={undefined}
sharedGroupNames={[]}
/>
}
2023-02-09 19:18:57 +00:00
title={username}
2023-03-08 23:41:32 +00:00
onClick={boundOnClick}
trailing={
isFetchingUsername ? (
<Spinner
size="20px"
svgSize="small"
moduleClassName={SPINNER_CLASS_NAME}
direction="on-progress-dialog"
/>
) : undefined
}
2021-11-12 01:17:29 +00:00
/>
);
2022-11-18 00:45:19 +00:00
}