Skip to content

Commit

Permalink
Merge pull request #196 from TheUpperPart/Fix/#195
Browse files Browse the repository at this point in the history
Fix/#195: 채팅에 발생하는 일부 에러 수정
  • Loading branch information
pp449 authored Oct 26, 2023
2 parents 1df5f31 + 3849ffc commit 21db013
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/RoundCheckIn/CallAdminChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from '@emotion/react';
import styled from '@emotion/styled';
import Image from 'next/image';
import { Client } from '@stomp/stompjs';
import React, { useEffect, useState, ChangeEvent } from 'react';
import React, { useEffect, useState, ChangeEvent, useRef } from 'react';
import { useRouter } from 'next/router';
import { BASE_PROFILE_IMG } from '@config/index';

Expand All @@ -26,6 +26,11 @@ const CallAdminChat = ({
const [inputMessage, setInputMessage] = useState('');
const router = useRouter();
const { channelLink } = router.query;
const chatEndRef = useRef<HTMLDivElement>(null);

const scrollToBottom = () => {
chatEndRef.current?.scrollIntoView({ behavior: 'smooth' });
};

const handleInputMessage = (e: ChangeEvent<HTMLInputElement>) => {
setInputMessage(e.target.value);
Expand Down Expand Up @@ -111,9 +116,13 @@ const CallAdminChat = ({

useEffect(() => {
if (!matchMessages || matchMessages.length === 0) return;
setChats(matchMessages);
setChats(matchMessages.reverse());
}, [matchMessages]);

useEffect(() => {
scrollToBottom();
}, [chats]);

return (
<Container>
<Header>
Expand Down Expand Up @@ -148,6 +157,7 @@ const CallAdminChat = ({
</ChattingContent>
</ChattingInfo>
))}
<div ref={chatEndRef} />
</ChattingWrapper>
<div
css={css`
Expand Down

0 comments on commit 21db013

Please sign in to comment.