mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-13 17:21:53 +00:00
Add picture in chat and button to dashboard
Took 28 minutes
This commit is contained in:
@@ -1,31 +1,28 @@
|
|||||||
import { Flex } from "@chakra-ui/react";
|
import {Flex} from '@chakra-ui/react';
|
||||||
import { MapContainer, TileLayer } from "react-leaflet";
|
import {MapContainer, TileLayer} from 'react-leaflet';
|
||||||
import SimpleMarkerBar from "./SimpleMarkerBar";
|
import SimpleMarkerBar from './SimpleMarkerBar';
|
||||||
import "leaflet/dist/leaflet.css";
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
|
||||||
type MapBarProps = {
|
type MapBarProps = {
|
||||||
lat: string;
|
lat: string;
|
||||||
lon: string;
|
lon: string;
|
||||||
name: string;
|
name: string;
|
||||||
align: "left" | "right";
|
align: 'left' | 'right';
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function MapBar({ lat, lon, name, align }: MapBarProps) {
|
export default function MapBar({lat, lon, name}: MapBarProps) {
|
||||||
return (
|
return (
|
||||||
<Flex justifyContent={align}>
|
|
||||||
<MapContainer
|
<MapContainer
|
||||||
center={[Number(lat), Number(lon)]}
|
center={[Number(lat), Number(lon)]}
|
||||||
zoom={13}
|
zoom={13}
|
||||||
minZoom={6}
|
minZoom={6}
|
||||||
zoomControl={false}
|
zoomControl={false}
|
||||||
style={{ width: "100%", height: "20rem" }}
|
style={{width: '100%', height: '20rem'}}>
|
||||||
>
|
|
||||||
<TileLayer
|
<TileLayer
|
||||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
/>
|
/>
|
||||||
<SimpleMarkerBar lat={lat} lon={lon} name={name} />
|
<SimpleMarkerBar lat={lat} lon={lon} name={name}/>
|
||||||
</MapContainer>
|
</MapContainer>
|
||||||
</Flex>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type {Message as MessageType} from '@prisma/client';
|
import type {Message as MessageType, User} from '@prisma/client';
|
||||||
import MessageText from '@/components/chat/MessageText';
|
import MessageText from '@/components/chat/MessageText';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import MessageMap from '@/components/chat/MessageMap';
|
import MessageMap from '@/components/chat/MessageMap';
|
||||||
@@ -6,9 +6,10 @@ import MessageMap from '@/components/chat/MessageMap';
|
|||||||
type Props = {
|
type Props = {
|
||||||
align: "left" | 'right'
|
align: "left" | 'right'
|
||||||
message: MessageType
|
message: MessageType
|
||||||
|
user?: User
|
||||||
}
|
}
|
||||||
|
|
||||||
const Message = ({message, align}: Props) => {
|
const Message = ({message, align, user}: Props) => {
|
||||||
if (message.text.match(/<!.+>/g)) {
|
if (message.text.match(/<!.+>/g)) {
|
||||||
const regex = /<!lon=(?<lon>-?\d+\.\d+),lat=(?<lat>-?\d+\.\d+),name=(?<name>.+)>/g;
|
const regex = /<!lon=(?<lon>-?\d+\.\d+),lat=(?<lat>-?\d+\.\d+),name=(?<name>.+)>/g;
|
||||||
const p = regex.exec(message.text)?.groups as unknown as {
|
const p = regex.exec(message.text)?.groups as unknown as {
|
||||||
@@ -16,12 +17,10 @@ const Message = ({message, align}: Props) => {
|
|||||||
lat: number
|
lat: number
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
if (p) return <MessageMap align={align} point={p}/>
|
if (p) return <MessageMap user={user} align={align} point={p}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <MessageText user={user} message={message} align={align} />
|
||||||
<MessageText message={message} align={align} />
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Message;
|
export default Message;
|
||||||
@@ -1,19 +1,24 @@
|
|||||||
import type {Message as MessageType, User} from '@prisma/client';
|
import type {Message as MessageType, User, Chat} from '@prisma/client';
|
||||||
import Message from '@/components/chat/Message';
|
import Message from '@/components/chat/Message';
|
||||||
import {Flex} from '@chakra-ui/react';
|
import {Flex} from '@chakra-ui/react';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user: User,
|
user: User,
|
||||||
messages: MessageType[]
|
messages: MessageType[]
|
||||||
|
chat: Chat & { User: User[] }
|
||||||
}
|
}
|
||||||
|
|
||||||
const MessageList = ({messages, user}: Props) => (
|
const MessageList = ({messages, user, chat}: Props) => {
|
||||||
<Flex direction={'column'} gap={1} justifyContent={'flex-end'}>
|
if (chat?.User)
|
||||||
{messages.map((message, index) => <Message
|
return (
|
||||||
align={user.id === message.UserID ? 'right' : 'left'} key={index}
|
<Flex direction={'column'} gap={1} justifyContent={'flex-end'}>
|
||||||
message={message}/>,
|
{messages.map((message, index) =>
|
||||||
)}
|
<Message user={chat.User.find(u => u.id === message.UserID)}
|
||||||
</Flex>
|
align={user.id === message.UserID ? 'right' : 'left'}
|
||||||
);
|
key={index} message={message}/>,
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default MessageList;
|
export default MessageList;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import {Box, Flex, Text} from '@chakra-ui/react';
|
import {Avatar, Box, Flex, Text} from '@chakra-ui/react';
|
||||||
|
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
|
import {User} from '@prisma/client';
|
||||||
|
|
||||||
const MapBarWithNoSSR = dynamic(() => import('./MapBar'), {
|
const MapBarWithNoSSR = dynamic(() => import('./MapBar'), {
|
||||||
ssr: false,
|
ssr: false,
|
||||||
@@ -13,16 +14,18 @@ type Props = {
|
|||||||
lat: string;
|
lat: string;
|
||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
user?: User
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function MessageMap({align, point}: Props) {
|
export default function MessageMap({align, point, user}: Props) {
|
||||||
const {lon, lat, name} = point;
|
const {lon, lat, name} = point;
|
||||||
return (
|
return (
|
||||||
<Flex justifyContent={align}>
|
<Flex justifyContent={align} gap={2}>
|
||||||
|
{user && align === "left" && <Avatar src={`/${user.images[0]}`} name={`${user.firstName} ${user.lastName}`}/>}
|
||||||
<Box w={'50%'} bg={'purple.500'} borderRadius={10} p={2}>
|
<Box w={'50%'} bg={'purple.500'} borderRadius={10} p={2}>
|
||||||
<MapBarWithNoSSR lon={lon} lat={lat} name={name}/>
|
<MapBarWithNoSSR lon={lon} lat={lat} name={name}/>
|
||||||
{/*<Text align={align}>{lon}, {lat}, {name}</Text>*/}
|
|
||||||
</Box>
|
</Box>
|
||||||
|
{user && align === "right" && <Avatar src={`/${user.images[0]}`} name={`${user.firstName} ${user.lastName}`}/>}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
import {Flex, Text} from '@chakra-ui/react';
|
import {Avatar, Flex, Text} from '@chakra-ui/react';
|
||||||
import type {Message as MessageType, User} from '@prisma/client';
|
import type {Message as MessageType, User} from '@prisma/client';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
align: 'left' | 'right'
|
align: 'left' | 'right'
|
||||||
message: MessageType
|
message: MessageType,
|
||||||
|
user?: User
|
||||||
}
|
}
|
||||||
|
|
||||||
const MessageText = ({message, align}: Props) => (
|
const MessageText = ({message, align, user}: Props) => (
|
||||||
<Flex justifyContent={align}>
|
|
||||||
|
<Flex justifyContent={align} gap={2}>
|
||||||
|
{user && align === "left" && <Avatar src={`/${user.images[0]}`} name={`${user.firstName} ${user.lastName}`}/>}
|
||||||
<Text maxW={'70%'} w={'fit-content'} bg={'purple.500'} borderRadius={10}
|
<Text maxW={'70%'} w={'fit-content'} bg={'purple.500'} borderRadius={10}
|
||||||
color={'white'} px={'10px'} py={'5px'}>
|
color={'white'} px={'10px'} py={'5px'}>
|
||||||
{message.text}
|
{message.text}
|
||||||
</Text>
|
</Text>
|
||||||
|
{user && align === "right" && <Avatar src={`/${user.images[0]}`} name={`${user.firstName} ${user.lastName}`}/>}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
Box,
|
Box, Button,
|
||||||
Container,
|
Container,
|
||||||
Flex,
|
Flex,
|
||||||
FormControl,
|
FormControl,
|
||||||
IconButton,
|
IconButton,
|
||||||
Input,
|
Input,
|
||||||
Text
|
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import {websiteName} from '@/lib/constants';
|
import {websiteName} from '@/lib/constants';
|
||||||
@@ -19,7 +18,8 @@ import {io, Socket} from 'socket.io-client';
|
|||||||
import {Chat, Message, User} from '@prisma/client';
|
import {Chat, Message, User} from '@prisma/client';
|
||||||
import LoadingPage from '@/components/LoadingPage';
|
import LoadingPage from '@/components/LoadingPage';
|
||||||
import Navbar from '@/components/Navbar';
|
import Navbar from '@/components/Navbar';
|
||||||
import {ArrowForwardIcon, CalendarIcon} from '@chakra-ui/icons';
|
|
||||||
|
import {ArrowForwardIcon} from '@chakra-ui/icons';
|
||||||
import {FaMapMarkedAlt} from 'react-icons/fa';
|
import {FaMapMarkedAlt} from 'react-icons/fa';
|
||||||
|
|
||||||
export default function ChatId() {
|
export default function ChatId() {
|
||||||
@@ -84,8 +84,8 @@ export default function ChatId() {
|
|||||||
|
|
||||||
<Navbar/>
|
<Navbar/>
|
||||||
|
|
||||||
<Container pt={20} bgColor={'white'}>
|
<Container maxW={'container.md'} pt={20} bgColor={'white'}>
|
||||||
<MessageList user={session.user as User} messages={messages}/>
|
<MessageList chat={chatInfo} user={session.user as User} messages={messages}/>
|
||||||
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
@@ -103,6 +103,8 @@ export default function ChatId() {
|
|||||||
</form>
|
</form>
|
||||||
<AlwaysScrollToBottom/>
|
<AlwaysScrollToBottom/>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
|
<Button m={3} position={'fixed'} bottom={0} onClick={() => router.push("/dashboard")}>Tableau de bord</Button>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user