@pubuduth-aplicy/chat-ui 2.2.20 → 2.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ const Messages = () => {
|
|
|
13
13
|
const { selectedConversation, setMessages, messages } = useChatUIStore();
|
|
14
14
|
const { userId, socket } = useChatContext();
|
|
15
15
|
const { ref, inView } = useInView();
|
|
16
|
-
const
|
|
16
|
+
const chatContainerRef = useRef<HTMLDivElement>(null);
|
|
17
17
|
|
|
18
18
|
const { data, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({
|
|
19
19
|
queryKey: ["messages", selectedConversation?._id, userId],
|
|
@@ -173,17 +173,21 @@ const Messages = () => {
|
|
|
173
173
|
};
|
|
174
174
|
}, [socket, selectedConversation?._id, setMessages, userId]);
|
|
175
175
|
|
|
176
|
-
// Scroll to bottom when
|
|
176
|
+
// Scroll to bottom when a new message is appended (sender or receiver)
|
|
177
|
+
const lastMessageId = messages[messages.length - 1]?._id;
|
|
177
178
|
useEffect(() => {
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
if (!lastMessageId) return;
|
|
180
|
+
const timer = setTimeout(() => {
|
|
181
|
+
const container = chatContainerRef.current;
|
|
182
|
+
if (container) {
|
|
183
|
+
container.scrollTo({
|
|
184
|
+
top: container.scrollHeight,
|
|
181
185
|
behavior: "smooth",
|
|
182
|
-
block: "nearest",
|
|
183
186
|
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
+
}
|
|
188
|
+
}, 100);
|
|
189
|
+
return () => clearTimeout(timer);
|
|
190
|
+
}, [lastMessageId]);
|
|
187
191
|
|
|
188
192
|
// Track message visibility for read receipts
|
|
189
193
|
// useEffect(() => {
|
|
@@ -211,8 +215,9 @@ const Messages = () => {
|
|
|
211
215
|
|
|
212
216
|
return (
|
|
213
217
|
<div
|
|
218
|
+
ref={chatContainerRef}
|
|
214
219
|
className="chatMessages"
|
|
215
|
-
style={{ overflowY: "auto",
|
|
220
|
+
style={{ overflowY: "auto", flex: "1 1 0%", minHeight: 0, position: "relative" }}
|
|
216
221
|
>
|
|
217
222
|
<SystemNotice />
|
|
218
223
|
<div ref={ref} className="my-8">
|
|
@@ -221,12 +226,7 @@ const Messages = () => {
|
|
|
221
226
|
{messages?.length > 0 ? (
|
|
222
227
|
messages?.map((message: any) =>
|
|
223
228
|
message ? (
|
|
224
|
-
<div
|
|
225
|
-
key={message._id}
|
|
226
|
-
ref={lastMessageRef}
|
|
227
|
-
data-message-id={message._id}
|
|
228
|
-
style={{ flex: 1, minHeight: 0, overflowY: "auto" }}
|
|
229
|
-
>
|
|
229
|
+
<div key={message._id} data-message-id={message._id}>
|
|
230
230
|
<Message message={message} />
|
|
231
231
|
</div>
|
|
232
232
|
) : null,
|