Skip to content

Commit

Permalink
scrolldown function done.
Browse files Browse the repository at this point in the history
  • Loading branch information
ch-vargaso committed Jun 30, 2023
1 parent 0318505 commit e37236d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions apps/codac-quasseln/src/pages/main-chat/[chatId].tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRouter } from "next/router";
import { gql, useQuery, useMutation } from "@apollo/client";
import React, { FormEvent, useState } from "react";
import React, { FormEvent, useEffect, useRef, useState } from "react";
import { useAuth } from "#/contexts/authContext";
import { timeStamp } from "console";
import Message from "#/components/chat/main-chat/message";
Expand Down Expand Up @@ -154,10 +154,6 @@ const SingleChat = (props: Props) => {
const deleteMsg = () => {
refetch()
}




// UPDATE PINNED CONVERSATION FUNCTION
const [updatePinnedMutation] = useMutation(updatePinnedConversation);
const updatePinned = async (
Expand Down Expand Up @@ -207,6 +203,15 @@ const SingleChat = (props: Props) => {
refetch,
} = useQuery(getChatHistoryById, { variables: { id: active } });

// FUNCTION TO SCROLL DOWN TO THE LAST MESSAGE IN THE CHAT
const messagesEndRef = React.useRef<HTMLDivElement>(null);
const scrollToBottom = () => {
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
}
useEffect(scrollToBottom, [allMessages]);



// do I need this chatHistory state????
// const [chatHistory, setChatHistory] = useState([]);
const [messageText, setMessageText] = useState("");
Expand Down Expand Up @@ -452,13 +457,14 @@ const SingleChat = (props: Props) => {
>
{allMessages &&
allMessages?.conversation?.data.attributes?.messages?.data?.map((message: any) => {

return <Message
message={message}
deleteMsg={deleteMsg}


/>;

})}
<div ref={messagesEndRef} />
</div>

{/* +++++++++++++++++++++++++ TEXT BODY +++++++++++++++++++ */}
Expand Down

0 comments on commit e37236d

Please sign in to comment.