diff --git a/client/app/(patient)/chats/@chatList/page.tsx b/client/app/(patient)/chats/@chatList/page.tsx index 890670c1..9932ce7e 100644 --- a/client/app/(patient)/chats/@chatList/page.tsx +++ b/client/app/(patient)/chats/@chatList/page.tsx @@ -8,26 +8,27 @@ import { useEffect, useState } from "react"; const Page = () => { const { data } = useGetDoctorsList(); const [isNewChatModalOpen, setNewChatModalOpen] = useState(false); - const [isLoading, setLoading] = useState(true) - const { chats, createChat, error, joinChatRoom } = useChats({ role: "patient", messagePath: "/chats" }) - const doctors: ChatModelUser[] = data?.items.map(({ _id, image, name }) => ({ _id, name, profilePicture: image })) || []; + const [isLoading, setLoading] = useState(true); + const { chats, createChat, error, joinChatRoom } = useChats({ role: "patient", messagePath: "/chats" }); + const [doctors, setDoctors] = useState([]) useEffect(() => { if (chats) { setLoading(false) } - }, [chats]); + setDoctors(prev => data?.items.map(({ _id, image, name }) => ({ _id, name, profilePicture: image })) || []) + }, [chats, data]); const handleCloseModal = () => { setNewChatModalOpen(false) } - + const handleJoinChat = (chatId: string) => { joinChatRoom(chatId); } - + const handleAddDoctorChat = (doctorId: string) => { setNewChatModalOpen(false); createChat(doctorId); diff --git a/client/app/doctor/chats/@chatList/page.tsx b/client/app/doctor/chats/@chatList/page.tsx index 3bebadac..259829a0 100644 --- a/client/app/doctor/chats/@chatList/page.tsx +++ b/client/app/doctor/chats/@chatList/page.tsx @@ -7,15 +7,17 @@ import useChats from "@/lib/hooks/useChats"; const Page = () => { const [isNewChatModalOpen, setNewChatModalOpen] = useState(false); const [isLoading, setLoading] = useState(true) - const { chats, createChat, error, joinChatRoom, patients, getPatients } = useChats({ role: "doctor", messagePath: "/doctor/chats" }) + const { + chats, createChat, error, joinChatRoom, patients, getPatients + } = useChats({ role: "doctor", messagePath: "/doctor/chats" }) + - useEffect(() => { if (chats && patients) { setLoading(false) } }, [chats, patients]); - + const handleJoinChat = (chatId: string) => { joinChatRoom(chatId); } @@ -29,7 +31,7 @@ const Page = () => { createChat(patientId); } - const handleClickNewChat = ()=>{ + const handleClickNewChat = () => { getPatients(); setNewChatModalOpen(true); } diff --git a/client/components/page-components/chat/ChatLayout.tsx b/client/components/page-components/chat/ChatLayout.tsx index 20ff4b98..7bdc85f9 100644 --- a/client/components/page-components/chat/ChatLayout.tsx +++ b/client/components/page-components/chat/ChatLayout.tsx @@ -2,34 +2,39 @@ import { ReactNode, useEffect, useState } from 'react' import { usePathname } from 'next/navigation' -import { useAuth } from '@/lib/hooks/useAuth'; -import ChatLayoutSkeleton from '@/components/skeletons/ChatSkelton'; -import NotAuthenticated from './NotAuthenticated'; +import { useAuth } from '@/lib/hooks/useAuth' +import ChatLayoutSkeleton from '@/components/skeletons/ChatSkelton' +import NotAuthenticated from './NotAuthenticated' export default function ChatLayout({ chatList, chat, isPatient }: { - chatList: ReactNode; - chat: ReactNode; - isPatient: boolean; + chatList: ReactNode + chat: ReactNode + isPatient: boolean }) { const pathname = usePathname(); const [isLoading, setLoading] = useState(true); - const isInChatView = pathname.startsWith('/chats/'); + const [isInChatView, setIsInChatView] = useState(false) const { patientToken } = useAuth(); + useEffect(() => { + setIsInChatView(pathname.includes('/chats/')) + }, [pathname]) + useEffect(() => { if (isPatient) { const timer = setTimeout(() => { - setLoading(false); - }, 0); - return () => clearTimeout(timer); + setLoading(false) + }, 0) + return () => clearTimeout(timer) } else { - setLoading(false); + setLoading(false) } - }, [isPatient ]); + }, [isPatient]); + if (isLoading) { return @@ -40,7 +45,7 @@ export default function ChatLayout({ } return ( -
+