formatting label for conversation list
This commit is contained in:
@@ -32,6 +32,7 @@ import useTerminal from './Terminal';
|
|||||||
import Conversation from '@nirvana/core/src/models/conversation.model';
|
import Conversation from '@nirvana/core/src/models/conversation.model';
|
||||||
import useAuth from '../providers/AuthProvider';
|
import useAuth from '../providers/AuthProvider';
|
||||||
import { useImmer } from 'use-immer';
|
import { useImmer } from 'use-immer';
|
||||||
|
import ConversationLabel from '../subcomponents/ConversationLabel';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -116,9 +117,9 @@ function ConversationRow({ conversation }: { conversation: Conversation }) {
|
|||||||
<FiCircle />
|
<FiCircle />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Typography sx={{ mr: 'auto', color: 'GrayText' }} variant={'overline'}>
|
<Box sx={{ mr: 'auto', color: 'GrayText' }}>
|
||||||
{conversationUsers.map((conversationUser) => conversationUser.displayName).join(', ')}
|
<ConversationLabel users={conversationUsers} conversationName={conversation.name} />
|
||||||
</Typography>
|
</Box>
|
||||||
|
|
||||||
<ListItemAvatar>
|
<ListItemAvatar>
|
||||||
<AvatarGroup variant={'rounded'}>
|
<AvatarGroup variant={'rounded'}>
|
||||||
|
|||||||
@@ -1,15 +1,46 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import Conversation from '@nirvana/core/src/models/conversation.model';
|
import Conversation from '@nirvana/core/src/models/conversation.model';
|
||||||
|
import { User } from '@nirvana/core/src/models/user.model';
|
||||||
|
import { Typography } from '@mui/material';
|
||||||
|
import useAuth from '../providers/AuthProvider';
|
||||||
|
|
||||||
|
type IConversationLabel =
|
||||||
|
| {
|
||||||
|
conversationName?: string;
|
||||||
|
users: User[];
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
conversationName: string;
|
||||||
|
users?: User[];
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if there is a name in the conversation, then return that
|
* if there is a name in the conversation, then return that
|
||||||
* if not, then return first three names
|
* if not, then return first three names
|
||||||
*/
|
*/
|
||||||
export default function ConversationLabel({ conversation }: { conversation: Conversation }) {
|
export default function ConversationLabel({ conversationName, users }: IConversationLabel) {
|
||||||
// if (conversation.memberIdsList?.length === 2) {
|
const { user } = useAuth();
|
||||||
|
|
||||||
// }
|
if (conversationName) {
|
||||||
|
return <Typography variant="overline">{conversationName}</Typography>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredUsers = users.filter((convoUser) => convoUser.id !== user.uid);
|
||||||
|
|
||||||
|
if (filteredUsers.length === 1) {
|
||||||
|
const firstName = filteredUsers[0].displayName.split(' ')[0];
|
||||||
|
|
||||||
|
return <Typography variant="overline">{firstName}</Typography>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filteredUsers.length > 1) {
|
||||||
|
const firstNames = filteredUsers.map((filteredUser) => filteredUser.displayName.split(' ')[0]);
|
||||||
|
|
||||||
|
const formattedFirstnames = firstNames.slice(0, -1).join(',') + ' and ' + firstNames.slice(-1);
|
||||||
|
|
||||||
|
return <Typography variant="overline">{formattedFirstnames}</Typography>;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user