2022-06-17 00:38:28 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
2023-01-25 23:51:08 +00:00
|
|
|
import type { FunctionComponent } from 'react';
|
2022-06-17 00:38:28 +00:00
|
|
|
|
|
|
|
import type { LocalizerType, ThemeType } from '../../types/Util';
|
|
|
|
import { AvatarColors } from '../../types/Colors';
|
|
|
|
import type { LookupConversationWithoutUuidActionsType } from '../../util/lookupConversationWithoutUuid';
|
2023-01-25 23:51:08 +00:00
|
|
|
import { ListTile } from '../ListTile';
|
|
|
|
import { Avatar, AvatarSize } from '../Avatar';
|
|
|
|
import { Spinner } from '../Spinner';
|
|
|
|
import { SPINNER_CLASS_NAME } from './BaseConversationListItem';
|
2022-06-17 00:38:28 +00:00
|
|
|
|
|
|
|
export type PropsDataType = {
|
|
|
|
username: string;
|
|
|
|
isChecked: boolean;
|
|
|
|
isFetching: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
type PropsHousekeepingType = {
|
|
|
|
i18n: LocalizerType;
|
|
|
|
theme: ThemeType;
|
|
|
|
toggleConversationInChooseMembers: (conversationId: string) => void;
|
|
|
|
} & LookupConversationWithoutUuidActionsType;
|
|
|
|
|
|
|
|
type PropsType = PropsDataType & PropsHousekeepingType;
|
|
|
|
|
|
|
|
export const UsernameCheckbox: FunctionComponent<PropsType> = React.memo(
|
|
|
|
function UsernameCheckbox({
|
|
|
|
username,
|
|
|
|
isChecked,
|
|
|
|
isFetching,
|
|
|
|
i18n,
|
|
|
|
lookupConversationWithoutUuid,
|
|
|
|
showUserNotFoundModal,
|
|
|
|
setIsFetchingUUID,
|
|
|
|
toggleConversationInChooseMembers,
|
|
|
|
}) {
|
|
|
|
const onClickItem = React.useCallback(async () => {
|
|
|
|
if (isFetching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const conversationId = await lookupConversationWithoutUuid({
|
|
|
|
showUserNotFoundModal,
|
|
|
|
setIsFetchingUUID,
|
|
|
|
|
|
|
|
type: 'username',
|
|
|
|
username,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (conversationId !== undefined) {
|
|
|
|
toggleConversationInChooseMembers(conversationId);
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
isFetching,
|
|
|
|
toggleConversationInChooseMembers,
|
|
|
|
lookupConversationWithoutUuid,
|
|
|
|
showUserNotFoundModal,
|
|
|
|
setIsFetchingUUID,
|
|
|
|
username,
|
|
|
|
]);
|
|
|
|
|
2023-02-09 19:18:57 +00:00
|
|
|
const title = username;
|
2022-06-17 00:38:28 +00:00
|
|
|
|
2023-01-25 23:51:08 +00:00
|
|
|
const avatar = (
|
|
|
|
<Avatar
|
2022-06-17 00:38:28 +00:00
|
|
|
acceptedMessageRequest={false}
|
|
|
|
color={AvatarColors[0]}
|
|
|
|
conversationType="direct"
|
2023-01-25 23:51:08 +00:00
|
|
|
searchResult
|
2022-06-17 00:38:28 +00:00
|
|
|
i18n={i18n}
|
|
|
|
isMe={false}
|
2023-01-25 23:51:08 +00:00
|
|
|
title={title}
|
2022-06-17 00:38:28 +00:00
|
|
|
sharedGroupNames={[]}
|
2023-01-25 23:51:08 +00:00
|
|
|
size={AvatarSize.THIRTY_TWO}
|
|
|
|
badge={undefined}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return isFetching ? (
|
|
|
|
<ListTile
|
|
|
|
leading={avatar}
|
2022-06-17 00:38:28 +00:00
|
|
|
title={title}
|
2023-01-25 23:51:08 +00:00
|
|
|
trailing={
|
|
|
|
<Spinner
|
|
|
|
size="20px"
|
|
|
|
svgSize="small"
|
|
|
|
moduleClassName={SPINNER_CLASS_NAME}
|
|
|
|
direction="on-progress-dialog"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<ListTile.checkbox
|
|
|
|
leading={avatar}
|
|
|
|
title={title}
|
|
|
|
isChecked={isChecked}
|
|
|
|
onClick={onClickItem}
|
|
|
|
clickable
|
2022-06-17 00:38:28 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|