@@ -5,31 +5,31 @@ import { Client, StompSubscription } from '@stomp/stompjs';
55import SockJS from 'sockjs-client' ;
66import { useEffect , useRef , useState } from 'react' ;
77import { MAX_CHAT_MESSAGE_LENGTH } from '@/constants' ;
8- import { loadChatHistory } from '@/apis/chat' ;
8+ import { loadChatHistoryDev } from '@/apis/chat' ;
99import { useAuthStore } from '@/store/authStore' ;
10- // import { getUserInfo } from '@/apis/user';
1110import { useScrollStore } from '@/store/scrollStore' ;
1211
12+ import dayjs from 'dayjs' ;
13+ import utc from 'dayjs/plugin/utc' ;
14+ import timezone from 'dayjs/plugin/timezone' ;
15+ import 'dayjs/locale/ko' ;
16+ dayjs . extend ( utc ) ;
17+ dayjs . extend ( timezone ) ;
18+
1319interface ChatRoomProps { }
1420
1521//메시지 타입
1622interface ChatMessage {
17- // fromUserId?: string;
18- message : string ;
23+ fromUserId ?: string ;
1924 chatRoomId : number ;
25+ message : string ;
2026 createdAt ?: string ;
2127 isMyMessage ?: boolean ;
2228}
23- // interface ChatUser {
24- // nickName: string;
25- // email: string;
26- // loginId: string;
27- // createdAt: string;
28- // }
2929
3030export default function ChatRoom ( { } : ChatRoomProps ) {
3131 // const [chatRoomId, setChatRoomId] = useState<number | null>(7);
32- const chatRoomId = 7 ;
32+ const chatRoomId = 1 ;
3333 // const [myUserData, setMyUserData] = useState<ChatUser | null>(null);
3434
3535 const [ stompClient , setStompClient ] = useState < Client | null > ( null ) ;
@@ -50,16 +50,6 @@ export default function ChatRoom({}: ChatRoomProps) {
5050
5151 const MAX_LINES = 8 ;
5252
53- // //내 정보 가져오기
54- // useEffect(() => {
55- // const getChatUser = async () => {
56- // const data = await getUserInfo();
57- // console.log(data);
58- // setMyUserData(data.data);
59- // };
60- // getChatUser();
61- // }, []);
62-
6353 const handleChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
6454 setMessageInput ( e . target . value ) ;
6555 } ;
@@ -128,13 +118,14 @@ export default function ChatRoom({}: ChatRoomProps) {
128118 console . log ( 'chatRoomId가 없습니다' ) ;
129119 return ;
130120 }
131- const response = await loadChatHistory ( chatRoomId ) ;
121+ //배포 시 변경
122+ const response = await loadChatHistoryDev ( chatRoomId ) ;
132123 console . log ( 'history' , response ) ;
133124 if ( response . status === 204 ) {
134125 console . warn ( 'No chat history found (204 No Content)' ) ;
135126 return ;
136127 }
137- setMessages ( response ) ;
128+ setMessages ( response . data ) ;
138129 } catch ( error ) {
139130 console . error ( 'Error fetching chat history:' , error ) ;
140131 }
@@ -200,6 +191,16 @@ export default function ChatRoom({}: ChatRoomProps) {
200191 }
201192 } ;
202193
194+ // 10분 연장 요청
195+ // const handleExtendSession = () => {
196+ // if (stompClient) {
197+ // stompClient.publish({
198+ // destination: '/app/extendSession',
199+ // body: JSON.stringify({}), // 빈 JSON 객체 전달
200+ // });
201+ // }
202+ // };
203+
203204 //채팅방 입장 시 connect
204205 //나갈 때 disconnect
205206 useEffect ( ( ) => {
@@ -251,13 +252,20 @@ export default function ChatRoom({}: ChatRoomProps) {
251252 } ) }
252253
253254 { /* 마지막 메시지의 시간 표시 */ }
254- < p className = "text-gray-500 text-xs text-center mt-2" > { messages . at ( - 1 ) ?. createdAt } </ p >
255+ { ! ! messages . length && (
256+ < p className = "text-gray-500 text-xs text-center mt-2" >
257+ { dayjs ( messages . at ( - 1 ) ?. createdAt )
258+ . tz ( 'Asia/Seoul' )
259+ . locale ( 'ko' )
260+ . format ( 'YYYY년 M월 D일 dddd' ) }
261+ </ p >
262+ ) }
255263 </ div >
256264
257- < div >
265+ { /* <div>
258266 <Button onClick={connect}>채팅 연결</Button>
259267 <Button onClick={disconnect}>채팅 연결 해제</Button>
260- </ div >
268+ </div> */ }
261269
262270 < div className = "bottom-padding-nav px-3 pt-[5px] bg-white max-w-[600px] fixed bottom-0 w-full left-1/2 -translate-x-1/2 z-41" >
263271 < div className = "flex justify-between mb-2 caption-b" >
0 commit comments