@@ -5,10 +5,11 @@ import Flex from "@/styles/Flex.styled";
55import Text from "@/styles/Text.styled" ;
66import Theme from "@/styles/Theme.styled" ;
77import { MessageData } from "@/types" ;
8+ import { getTime } from "@/utils/date" ;
89import Image from "next/image" ;
910import React , { useContext , useEffect , useRef } from "react" ;
1011import { VscAccount } from "react-icons/vsc" ;
11- import { PropagateLoader } from "react-spinners" ;
12+ import { PulseLoader } from "react-spinners" ;
1213
1314const ScrollableChat = ( { messages, isTyping } : { messages : MessageData [ ] ; isTyping : boolean } ) => {
1415 const { isDark } = useContext ( DarkLightModeContext ) ! ;
@@ -33,56 +34,67 @@ const ScrollableChat = ({ messages, isTyping }: { messages: MessageData[]; isTyp
3334 } , [ messages , isTyping ] ) ;
3435
3536 return (
36- < Flex
37- as = { "div" }
38- $overflowY = "auto"
39- flexDirection = "column"
40- gap = "12px"
41- height = "-webkit-fill-available"
42- margin = "12px 0"
43- ref = { messageContainerRef }
44- >
45- { messages &&
46- messages . map ( ( message , index ) => (
47- < Flex
48- key = { message . _id }
49- alignItems = "center"
50- gap = "12px"
51- margin = "0 12px 0 0"
52- $alignSelf = { message . sender . _id === user ?. _id ? "flex-end" : "flex-start" }
53- >
54- { isSameSender ( messages , message , index , user ?. _id ) || isLastMessage ( messages , index , user ?. _id ) ? (
55- < Container
56- width = "40px"
57- height = "40px"
58- padding = "8px"
59- backgroundColor = { Theme . colors . violet }
60- borderRadius = "12px"
61- hBackgroundColor = { Theme . colors . lightViolet }
62- cursor = "pointer"
63- >
64- { user ?. pic !== defaultProfileUrl ? (
65- < VscAccount size = { 24 } fill = { isDark ? Theme . colors . black : Theme . colors . white } />
66- ) : (
67- < Image
68- src = { message ?. sender ?. pic || "" }
69- alt = { message ?. sender ?. name || "user profile photo" }
70- width = { 24 }
71- height = { 24 }
72- style = { { borderRadius : "100%" } }
73- />
74- ) }
75- </ Container >
76- ) : (
77- < Container width = "32px" height = "32px" padding = "4px" $display = "hidden" > </ Container >
78- ) }
79- < Text color = { isDark ? Theme . colors . white : Theme . colors . black } > { message . content } </ Text >
80- </ Flex >
81- ) ) }
82- < Flex $alignSelf = "flex-start" height = "16px" >
83- { isTyping && < PropagateLoader color = { Theme . colors . violet } size = { 10 } /> }
37+ < >
38+ < Flex
39+ as = { "div" }
40+ $overflowY = "auto"
41+ flexDirection = "column"
42+ gap = "12px"
43+ height = "-webkit-fill-available"
44+ margin = "12px 0 0"
45+ ref = { messageContainerRef }
46+ >
47+ { messages &&
48+ messages . map ( ( message , index ) => (
49+ < Flex
50+ key = { message . _id }
51+ alignItems = "center"
52+ gap = "12px"
53+ margin = "0 12px 0 0"
54+ $alignSelf = { message . sender . _id === user ?. _id ? "flex-end" : "flex-start" }
55+ >
56+ { isSameSender ( messages , message , index , user ?. _id ) || isLastMessage ( messages , index , user ?. _id ) ? (
57+ < Container
58+ width = "40px"
59+ height = "40px"
60+ padding = "8px"
61+ backgroundColor = { Theme . colors . violet }
62+ borderRadius = "12px"
63+ hBackgroundColor = { Theme . colors . lightViolet }
64+ cursor = "pointer"
65+ >
66+ { user ?. pic !== defaultProfileUrl ? (
67+ < VscAccount size = { 24 } fill = { isDark ? Theme . colors . black : Theme . colors . white } />
68+ ) : (
69+ < Image
70+ src = { message ?. sender ?. pic || "" }
71+ alt = { message ?. sender ?. name || "user profile photo" }
72+ width = { 24 }
73+ height = { 24 }
74+ style = { { borderRadius : "100%" } }
75+ />
76+ ) }
77+ </ Container >
78+ ) : (
79+ < Container width = "40px" height = "40px" padding = "4px" $display = "hidden" > </ Container >
80+ ) }
81+ < Flex gap = "12px" alignItems = "center" >
82+ < Text fontSize = "18px" color = { isDark ? Theme . colors . white : Theme . colors . black } >
83+ { message . content }
84+ </ Text >
85+ < Flex $alignSelf = "flex-end" >
86+ < Text fontSize = "12px" color = { isDark ? Theme . colors . lightGrey : Theme . colors . extraDarkGrey } >
87+ { getTime ( message . createdAt , false ) }
88+ </ Text >
89+ </ Flex >
90+ </ Flex >
91+ </ Flex >
92+ ) ) }
8493 </ Flex >
85- </ Flex >
94+ < Flex $alignSelf = "flex-start" margin = "6px 0" height = "24px" alignItems = "center" >
95+ { isTyping ? < PulseLoader color = { Theme . colors . violet } size = { 10 } /> : < Container height = "14px" > </ Container > }
96+ </ Flex >
97+ </ >
8698 ) ;
8799} ;
88100
0 commit comments