mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-12-05 17:30:50 +00:00
Display Chats in dashboard + autoscroll chat to bottom
Took 1 hour 11 minutes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {Chat, User} from '@prisma/client';
|
||||
import ChatListItem from '@/components/chat/ChatListItem';
|
||||
import {useEffect, useState} from 'react';
|
||||
import {Stack, StackDivider} from '@chakra-ui/react';
|
||||
|
||||
type Props = {
|
||||
user: User
|
||||
@@ -18,11 +19,11 @@ export default function ChatList({user}: Props) {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack divider={<StackDivider/>} spacing={2}>
|
||||
{chats.map(
|
||||
(chat: Chat & { User: User[] }, index: number) =>
|
||||
<ChatListItem key={index} chat={chat} user={user}/>)
|
||||
}
|
||||
</>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -1,26 +1,24 @@
|
||||
import {Chat, User} from '@prisma/client';
|
||||
import {Box, Flex, Image, Text} from '@chakra-ui/react';
|
||||
import {Box, Button, Flex, Image, Text} from '@chakra-ui/react';
|
||||
import {useRouter} from 'next/router';
|
||||
|
||||
type Props = {
|
||||
user: User,
|
||||
chat: Chat & {User: User[]}
|
||||
chat: Chat & { User: User[] }
|
||||
};
|
||||
|
||||
export default function ChatListItem({user, chat}: Props) {
|
||||
const router = useRouter();
|
||||
const otherUser = chat.User.find((u: User) => u.id !== user.id) as User
|
||||
const otherUser = chat.User.find((u: User) => u.id !== user.id) as User;
|
||||
|
||||
console.log(chat);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Flex cursor={"pointer"} onClick={() => router.push(`/chat/${chat.id}`)}>
|
||||
<Image borderRadius={'full'} boxSize='50px' src={otherUser.images[0] ?? "/blank_profile_picture.webp"}/>
|
||||
<Box>
|
||||
<Text>{otherUser.firstName} {otherUser.lastName}</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
</>
|
||||
<Flex alignItems={"center"} gap={5} cursor={'pointer'} onClick={() => router.push(`/chat/${chat.id}`)}>
|
||||
<Image borderRadius={'full'} boxSize="50px" src={otherUser.images[0] ?? '/blank_profile_picture.webp'}/>
|
||||
<Box>
|
||||
<Text>{otherUser.firstName} {otherUser.lastName}</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type {Message as MessageType, User} from '@prisma/client';
|
||||
import Message from '@/components/chat/Message';
|
||||
import {Flex} from '@chakra-ui/react';
|
||||
import {Flex, Box} from '@chakra-ui/react';
|
||||
|
||||
type Props = {
|
||||
user: User,
|
||||
@@ -9,12 +9,14 @@ type Props = {
|
||||
|
||||
const MessageList = ({messages, user}: Props) => {
|
||||
return (
|
||||
<Flex direction={'column'} gap={1}>
|
||||
{messages.map((message, index) => <Message
|
||||
align={user.id === message.UserID ? 'right' : 'left'} key={index}
|
||||
message={message}/>
|
||||
)}
|
||||
</Flex>
|
||||
<Box w={'70vh'} overflow={'scroll'}>
|
||||
<Flex direction={'column'} gap={1} justifyContent={'flex-end'}>
|
||||
{messages.map((message, index) => <Message
|
||||
align={user.id === message.UserID ? 'right' : 'left'} key={index}
|
||||
message={message}/>,
|
||||
)}
|
||||
</Flex>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user