diff --git a/src/components/Carousel.tsx b/src/components/Carousel.tsx index 67fc6cd..3fde1ce 100644 --- a/src/components/Carousel.tsx +++ b/src/components/Carousel.tsx @@ -23,7 +23,7 @@ const Carousel = ({images, borderRadius: bRadius}: Props) => { return ( diff --git a/src/components/chat/ChatList.tsx b/src/components/chat/ChatList.tsx index 6c7752c..4ceb28d 100644 --- a/src/components/chat/ChatList.tsx +++ b/src/components/chat/ChatList.tsx @@ -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 ( - <> + } spacing={2}> {chats.map( (chat: Chat & { User: User[] }, index: number) => ) } - + ); } \ No newline at end of file diff --git a/src/components/chat/ChatListItem.tsx b/src/components/chat/ChatListItem.tsx index 0c223a0..319693c 100644 --- a/src/components/chat/ChatListItem.tsx +++ b/src/components/chat/ChatListItem.tsx @@ -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 ( - <> - router.push(`/chat/${chat.id}`)}> - - - {otherUser.firstName} {otherUser.lastName} - - - + router.push(`/chat/${chat.id}`)}> + + + {otherUser.firstName} {otherUser.lastName} + + ); } \ No newline at end of file diff --git a/src/components/chat/MessageList.tsx b/src/components/chat/MessageList.tsx index e596b3c..4448e81 100644 --- a/src/components/chat/MessageList.tsx +++ b/src/components/chat/MessageList.tsx @@ -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 ( - - {messages.map((message, index) => - )} - + + + {messages.map((message, index) => , + )} + + ); }; diff --git a/src/components/layout/dashboard/card_user/CardUser.tsx b/src/components/layout/dashboard/card_user/CardUser.tsx index 60022f9..3bdb560 100644 --- a/src/components/layout/dashboard/card_user/CardUser.tsx +++ b/src/components/layout/dashboard/card_user/CardUser.tsx @@ -17,13 +17,16 @@ import PassionTagList from "@/components/layout/dashboard/card_user/PassionTagLi import { useState } from "react"; import SearchFailCard from "./SearchFailCard"; import LoadingPage from "@/components/LoadingPage"; +import {User} from '@prisma/client'; -export default function CardUser({ - users, - loggedUser, - setMatch, - refetchLoggedUser, -}) { +type Props = { + users: User[] + loggedUser: User + setMatch: any + refetchLoggedUser: any +} + +export default function CardUser({users, loggedUser, setMatch, refetchLoggedUser}: Props) { const toast = useToast({ position: "top", duration: 2000, diff --git a/src/components/layout/dashboard/left_panel/LeftPanel.tsx b/src/components/layout/dashboard/left_panel/LeftPanel.tsx index 94ebf75..1badb23 100644 --- a/src/components/layout/dashboard/left_panel/LeftPanel.tsx +++ b/src/components/layout/dashboard/left_panel/LeftPanel.tsx @@ -68,13 +68,6 @@ export default function LeftPanel(props) { Carte - } - onClickHandler={() => router.push("/chat")} - > - Messages - - } onClickHandler={() => router.push("/profile")} diff --git a/src/pages/chat/[id].tsx b/src/pages/chat/[id].tsx index 92d4a6a..a6beffd 100644 --- a/src/pages/chat/[id].tsx +++ b/src/pages/chat/[id].tsx @@ -1,15 +1,16 @@ -import {Button, Container, Flex, Input} from '@chakra-ui/react'; +import {Button, Container, Flex, FormControl, Input} from '@chakra-ui/react'; import Head from 'next/head'; import {websiteName} from '@/lib/constants'; import {useSession} from 'next-auth/react'; import {useRouter} from 'next/router'; -import {useEffect, useState} from 'react'; +import {useEffect, useRef, useState} from 'react'; import MessageList from '@/components/chat/MessageList'; import {io, Socket} from 'socket.io-client'; import {Message, User} from '@prisma/client'; import LoadingPage from '@/components/LoadingPage'; +import Navbar from '@/components/Navbar'; export default function ChatId() { const router = useRouter(); @@ -30,33 +31,51 @@ export default function ChatId() { const soc = io(); soc.on('connect', () => console.log('connected')); - soc.on('allOldMessages', (allOldMessages: Message[]) => setMessages(allOldMessages)); - soc.on('newIncomingMessage', (newIncomingMessage: Message) => setMessages(messages => [...messages, newIncomingMessage])); + soc.on('allOldMessages', + (allOldMessages: Message[]) => setMessages(allOldMessages)); + soc.on('newIncomingMessage', + (newIncomingMessage: Message) => setMessages( + messages => [...messages, newIncomingMessage])); setSocket(soc); }); }; - const handleSubmit = () => { + const handleSubmit = (evt) => { + evt.preventDefault() if (text !== '' && socket && session?.user) { socket.emit('createdMessage', {text, sender: session.user.id}); setText(''); } }; + const AlwaysScrollToBottom = () => { + const elementRef = useRef(); + useEffect(() => elementRef.current.scrollIntoView()); + return
; + }; + if (status === 'loading') return ; return ( <> {websiteName} + + - - setText(evt.target.value)} value={text}/> - - + +
+ + + setText(evt.target.value)} + value={text}/> + + + +
+
); diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 25c808a..43b58ba 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -7,8 +7,5 @@ export default function Chat() { const {data: session, status} = useSession({required: true}); if (status === 'loading') return ; - if (session) - return ( - - ); + return ; } \ No newline at end of file diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 0e0e386..0ebc018 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -1,25 +1,34 @@ -import { Grid, GridItem, Box, useToast, useDisclosure } from "@chakra-ui/react"; -import { useSession } from "next-auth/react"; -import { useRouter } from "next/router"; -import { useState } from "react"; +import { + Grid, + GridItem, + Box, + useToast, + useDisclosure, + Card, CardBody, CardHeader, Heading, +} from '@chakra-ui/react'; +import {useSession} from 'next-auth/react'; +import {useRouter} from 'next/router'; -import type { Session } from "@/models/auth/Session"; -import CardUser from "../components/layout/dashboard/card_user/CardUser"; -import SearchFailCard from "../components/layout/dashboard/card_user/SearchFailCard"; +import type {Session} from '@/models/auth/Session'; +import CardUser from '../components/layout/dashboard/card_user/CardUser'; +import SearchFailCard + from '../components/layout/dashboard/card_user/SearchFailCard'; -import LeftPanel from "../components/layout/dashboard/left_panel/LeftPanel"; -import ModalMatch from "@/components/layout/dashboard/match_notification/ModalMatch"; -import Head from "next/head"; -import { websiteName } from "@/lib/constants"; -import { useQuery } from "@tanstack/react-query"; -import LoadingPage from "@/components/LoadingPage"; -import { Notification, NotificationType } from "@prisma/client"; +import LeftPanel from '../components/layout/dashboard/left_panel/LeftPanel'; +import ModalMatch + from '@/components/layout/dashboard/match_notification/ModalMatch'; +import Head from 'next/head'; +import {websiteName} from '@/lib/constants'; +import {useQuery} from '@tanstack/react-query'; +import LoadingPage from '@/components/LoadingPage'; +import {Notification, NotificationType, User} from '@prisma/client'; +import ChatList from '@/components/chat/ChatList'; export default function Dashboard() { const router = useRouter(); - const toast = useToast({ position: "top", isClosable: true }); + const toast = useToast({position: 'top', isClosable: true}); - const { data: session, status } = useSession(); + const {data: session, status} = useSession({required: true}); const { isLoading, @@ -28,18 +37,18 @@ export default function Dashboard() { error, refetch: refetchLoggedUser, } = useQuery({ - queryKey: ["LoggedUser"], - enabled: status === "authenticated", + queryKey: ['LoggedUser'], + enabled: status === 'authenticated', queryFn: async () => { - const { user } = session as unknown as Session; + const {user} = session as unknown as Session; return fetch(`/api/users/${user.id}?include=Notification`) - .then((res) => { - return res.json(); - }) - .catch((err) => { - return err; - }); + .then((res) => { + return res.json(); + }) + .catch((err) => { + return err; + }); }, }); @@ -49,84 +58,89 @@ export default function Dashboard() { isLoading: isLoadingListUsers, error: errorListUsers, } = useQuery({ - queryKey: ["ListUsers"], - enabled: status === "authenticated" && !isLoading, + queryKey: ['ListUsers'], + enabled: status === 'authenticated' && !isLoading, queryFn: async () => { - return fetch(`/api/user/userDashboard?userID=${loggedUser.id}`) //exclure les profils déjà like ou dislike - .then((res) => res.json()) - .catch((err) => { - return err; - }); + return fetch( + `/api/user/userDashboard?userID=${loggedUser.id}`) //exclure les profils déjà like ou dislike + .then((res) => res.json()) + .catch((err) => { + return err; + }); }, }); if (isLoading) { - if (status === "unauthenticated") router.push("/login"); - return ; + if (status === 'unauthenticated') router.push('/login'); + return ; } if (isError) { toast({ title: `Erreur lors de la récupération des données du profil`, - status: "error", - position: "top", + status: 'error', + position: 'top', }); - if (status === "unauthenticated") router.push("/"); + if (status === 'unauthenticated') router.push('/'); } let modal; if (loggedUser?.Notification?.length > 0) { const matchNotification = loggedUser.Notification.filter( - (notif: Notification) => - notif.type === NotificationType.NEW_MATCH && - notif.hasBeenConsulted === false + (notif: Notification) => + notif.type === NotificationType.NEW_MATCH && + notif.hasBeenConsulted === false, ); modal = matchNotification.map((notif: Notification) => { return ( - + ); }); } + if (status === 'loading') return ; return ( - <> - {modal} + <> + {modal} - - {websiteName} | Dashboard - + + {websiteName} | Dashboard + - - - - - - - {isLoadingListUsers ? ( - - ) : isErrorListUsers || - listUsers === undefined || - listUsers.users === undefined || - listUsers.users.length === 0 ? ( - - ) : ( - - )} - - - {/*Right top*/} - {/*Right Bottom*/} - - + + + + + + + {isLoadingListUsers + ? () + : (isErrorListUsers || !listUsers || !listUsers.users || + listUsers.users.length === 0) + ? + : + } + + + + + + + {router.push('/chat')}}>Conversations + + + + + + + + {/*Right Bottom*/} + + ); }