diff --git a/src/pages/chatting/Chatting.tsx b/src/pages/chatting/Chatting.tsx index a01ce692..1db7e401 100644 --- a/src/pages/chatting/Chatting.tsx +++ b/src/pages/chatting/Chatting.tsx @@ -42,7 +42,7 @@ const Chatting = () => { const getDetailMessages = async () => { try { const response = await axiosAPI.get(`/v1/chatting/rooms/${chatroomId}`) - console.log(response) + setMessages(response.data.chats) } catch (error) { console.error('Message fetching error') @@ -74,7 +74,7 @@ const Chatting = () => { if (!client.current.connected) return client.current.subscribe(`/sub/chatting/rooms/${chatroomId}`, (response) => { const JsonBody = JSON.parse(response.body) - console.log(response.body) + setMessages((_chatList) => [..._chatList, JsonBody]) }) } @@ -82,6 +82,7 @@ const Chatting = () => { const handleSubmit = (e: FormEvent) => { e.preventDefault() messageRef.current && send(messageRef.current.value) + if (messageRef.current) messageRef.current.value = '' } const handleClickExitRoom = () => { openModal({ @@ -98,15 +99,18 @@ const Chatting = () => { const navigateHome = () => { navigate('/') } - const handleKeyDown = (e: { key: string }) => { - if (e.key == 'Enter') { + const handleKeyDown = (event: React.KeyboardEvent) => { + if (event.nativeEvent.isComposing) { + return + } + if (event.key == 'Enter') { messageRef.current && send(messageRef.current.value) } } const send = (message: string) => { if (client.current) { if (!client.current.connected) return - console.log(message) + if (messageRef.current) messageRef.current.value = '' client.current.publish({ destination: '/pub/chatting/messages',