user row but autocomplete stop working
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { HTMLAttributes, useCallback, useState } from 'react';
|
import React, { HTMLAttributes, useCallback, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
|
AutocompleteChangeReason,
|
||||||
AutocompleteRenderOptionState,
|
AutocompleteRenderOptionState,
|
||||||
Button,
|
Button,
|
||||||
Container,
|
Container,
|
||||||
@@ -23,6 +24,7 @@ import { useDebounce } from 'react-use';
|
|||||||
import { searchUsers } from '../firebase/firestore';
|
import { searchUsers } from '../firebase/firestore';
|
||||||
import { User } from '@nirvana/core/src/models/user.model';
|
import { User } from '@nirvana/core/src/models/user.model';
|
||||||
import useAuth from '../providers/AuthProvider';
|
import useAuth from '../providers/AuthProvider';
|
||||||
|
import UserDetailRow from '../subcomponents/UserDetailRow';
|
||||||
|
|
||||||
export default function NewConversationDialog({
|
export default function NewConversationDialog({
|
||||||
open,
|
open,
|
||||||
@@ -40,9 +42,24 @@ export default function NewConversationDialog({
|
|||||||
|
|
||||||
const [selectedUsers, setSelectedUsers] = useState<User[]>([]);
|
const [selectedUsers, setSelectedUsers] = useState<User[]>([]);
|
||||||
|
|
||||||
const handleSelectUser = useCallback((event, newValue: User[]) => {
|
const handleChangeSelections = useCallback(
|
||||||
setSelectedUsers(newValue);
|
(e: React.SyntheticEvent<Element, Event>, value: User[], reason: AutocompleteChangeReason) => {
|
||||||
}, []);
|
const newUsers: User[] = [];
|
||||||
|
|
||||||
|
value.forEach((val) => {
|
||||||
|
if (typeof val !== 'string') return;
|
||||||
|
|
||||||
|
newUsers.push(val);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(value);
|
||||||
|
|
||||||
|
console.log(newUsers);
|
||||||
|
|
||||||
|
setSelectedUsers(newUsers);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
const [, cancel] = useDebounce(
|
const [, cancel] = useDebounce(
|
||||||
async () => {
|
async () => {
|
||||||
@@ -83,7 +100,7 @@ export default function NewConversationDialog({
|
|||||||
const renderOption = useCallback(
|
const renderOption = useCallback(
|
||||||
(props: HTMLAttributes<HTMLLIElement>, option: User, state: AutocompleteRenderOptionState) => (
|
(props: HTMLAttributes<HTMLLIElement>, option: User, state: AutocompleteRenderOptionState) => (
|
||||||
<ListItem {...props}>
|
<ListItem {...props}>
|
||||||
<Typography>{option.email}</Typography>
|
<UserDetailRow user={option} />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
),
|
),
|
||||||
[],
|
[],
|
||||||
@@ -127,6 +144,7 @@ export default function NewConversationDialog({
|
|||||||
renderOption={renderOption}
|
renderOption={renderOption}
|
||||||
getOptionLabel={(option) => (typeof option === 'string' ? option : option.displayName)}
|
getOptionLabel={(option) => (typeof option === 'string' ? option : option.displayName)}
|
||||||
value={selectedUsers}
|
value={selectedUsers}
|
||||||
|
onChange={handleChangeSelections}
|
||||||
filterSelectedOptions
|
filterSelectedOptions
|
||||||
filterOptions={(options) => options}
|
filterOptions={(options) => options}
|
||||||
inputValue={searchVal}
|
inputValue={searchVal}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { Avatar, Box, Stack, Typography } from '@mui/material';
|
||||||
|
import { User } from '@nirvana/core/src/models/user.model';
|
||||||
|
|
||||||
|
export default function UserDetailRow({
|
||||||
|
user,
|
||||||
|
rightContent,
|
||||||
|
}: {
|
||||||
|
user: User;
|
||||||
|
rightContent?: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction={'row'}
|
||||||
|
alignItems="center"
|
||||||
|
spacing={1}
|
||||||
|
sx={{
|
||||||
|
px: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Avatar src={user.photoUrl} alt={user.displayName} />
|
||||||
|
|
||||||
|
<Stack>
|
||||||
|
<Typography variant="subtitle2" color="info">
|
||||||
|
{user.displayName}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant={'overline'}>{user.email}</Typography>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
ml: 'auto',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{rightContent}
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user