@@ -5,7 +5,8 @@ import ProgressBar from '@chat/components/ProgressBar';
55import ChatMessage from '@chat/components/ChatMessage' ;
66import ChatForm from '@chat/components/ChatForm' ;
77import ChatMenu from '@shared/assets/icons/ChatMenuicon.svg' ;
8- import aiLogo from '../../../../public/favicon.svg' ;
8+ // public 폴더의 assets는 URL로 접근
9+ const aiLogo = '/favicon.svg' ;
910import theme from '@app/styles/theme' ;
1011import SuspendModal from '@chat/components/SuspendModal' ;
1112import SuccessModal from '@chat/components/SuccessModal' ;
@@ -34,7 +35,7 @@ const Chat = () => {
3435 progress,
3536 incrementProgress,
3637 } = useChatStore();*/
37- useEffect ( ( ) => {
38+ useEffect ( ( ) => {
3839 if ( params . sessionId ) {
3940 setCurrentSessionId ( params . sessionId ) ;
4041 return ;
@@ -48,13 +49,15 @@ const Chat = () => {
4849 } , [ location . pathname , params . sessionId ] ) ;
4950
5051 const { data : chatHistoryData , error : historyError } = useChatHistoryQuery (
51- currentSessionId , ! ! currentSessionId
52+ currentSessionId ,
53+ ! ! currentSessionId ,
5254 ) ;
5355
5456 // 채팅 내역을 메시지 형태로 변환하는 함수
5557 const convertApiMessagesToState = ( apiMessages ) => {
5658 if ( ! apiMessages || ! Array . isArray ( apiMessages ) ) return [ ] ;
5759
60+
5861 return apiMessages . map ( ( msg , index ) => {
5962 let cleanedContent = msg . content ;
6063
@@ -74,12 +77,18 @@ const Chat = () => {
7477
7578 // 채팅 내역 로드 완료 시 메시지 설정
7679 useEffect ( ( ) => {
77- if ( chatHistoryData ?. result ?. messages && Array . isArray ( chatHistoryData . result . messages ) && chatHistoryData . result . messages . length > 0 ) {
80+ if (
81+ chatHistoryData ?. result ?. messages &&
82+ Array . isArray ( chatHistoryData . result . messages ) &&
83+ chatHistoryData . result . messages . length > 0
84+ ) {
7885 const convertedMessages = convertApiMessagesToState ( chatHistoryData . result . messages ) ;
7986 setMessages ( convertedMessages ) ;
80-
87+
8188 // 프로그레스 계산 (AI 메시지 개수 * 10, 최대 100)
82- const aiMessageCount = chatHistoryData . result . messages . filter ( msg => msg . type === 'ai' ) . length ;
89+ const aiMessageCount = chatHistoryData . result . messages . filter (
90+ ( msg ) => msg . type === 'ai' ,
91+ ) . length ;
8392 setProgress ( Math . min ( aiMessageCount * 10 , 100 ) ) ;
8493 }
8594 // chatHistoryData가 있지만 messages가 비어있는 경우는 무시 (새로운 세션이므로 초기 메시지 유지)
@@ -129,6 +138,7 @@ const Chat = () => {
129138 } , [ messages ] ) ;
130139
131140 const handleChatSuccess = ( aiResponse , fullResponse ) => {
141+
132142 // "AI:" 접두사와 ** 마크다운 문자 제거
133143 const cleanedResponse = aiResponse . replace ( / ^ A I : \s * / , '' ) . replace ( / \* \* / g, '' ) ;
134144
@@ -139,9 +149,9 @@ const Chat = () => {
139149 timestamp : new Date ( ) ,
140150 } ;
141151
142- setMessages ( prev => [ ...prev , aiMessage ] ) ;
152+ setMessages ( ( prev ) => [ ...prev , aiMessage ] ) ;
143153
144- setProgress ( prev => Math . min ( prev + 10 , 100 ) ) ;
154+ setProgress ( ( prev ) => Math . min ( prev + 10 , 100 ) ) ;
145155
146156 setIsLoading ( false ) ;
147157 } ;
@@ -150,7 +160,7 @@ const Chat = () => {
150160 console . error ( '채팅 전송 실패:' , error ) ;
151161 } ;
152162
153- const sendChatMutation = useSendChatMutation ( handleChatSuccess , handleChatError ) ;
163+ const sendChatMutation = useSendChatMutation ( handleChatSuccess , handleChatError ) ;
154164
155165 const handleSendMessage = async ( text ) => {
156166 if ( ! text . trim ( ) || isLoading ) return ;
@@ -164,7 +174,7 @@ const Chat = () => {
164174 timestamp : new Date ( ) ,
165175 } ;
166176
167- setMessages ( prev => [ ...prev , userMessage ] ) ;
177+ setMessages ( ( prev ) => [ ...prev , userMessage ] ) ;
168178
169179 try {
170180 await sendChat ( text , currentSessionId , sendChatMutation ) ;
@@ -199,24 +209,24 @@ const Chat = () => {
199209 ) }
200210 </ TopContainer >
201211 < MessageContainer >
202- < MessageList ref = { messageListRef } >
203- { messages . map ( ( message ) => (
204- < ChatMessage key = { message . id } message = { message } />
205- ) ) }
206- { isLoading && (
207- < LoadingMessage >
208- < ProfileMark src = { aiLogo } />
209- < LoadingBubble >
210- < LoadingDots >
211- < Dot />
212- < Dot />
213- < Dot />
214- </ LoadingDots >
215- </ LoadingBubble >
216- </ LoadingMessage >
217- ) }
218- </ MessageList >
219- < ChatForm onSendMessage = { handleSendMessage } isLoading = { isLoading } />
212+ < MessageList ref = { messageListRef } >
213+ { messages . map ( ( message ) => (
214+ < ChatMessage key = { message . id } message = { message } />
215+ ) ) }
216+ { isLoading && (
217+ < LoadingMessage >
218+ < ProfileMark src = { aiLogo } />
219+ < LoadingBubble >
220+ < LoadingDots >
221+ < Dot />
222+ < Dot />
223+ < Dot />
224+ </ LoadingDots >
225+ </ LoadingBubble >
226+ </ LoadingMessage >
227+ ) }
228+ </ MessageList >
229+ < ChatForm onSendMessage = { handleSendMessage } isLoading = { isLoading } />
220230 </ MessageContainer >
221231 </ ChatContainer >
222232 { isSuspendModalOpen && < SuspendModal onClose = { handleSuspendModalClose } /> }
@@ -336,7 +346,8 @@ const FinishButton = styled.button`
336346 }
337347` ;
338348
339- const MessageContainer = styled . div ` display: flex;
349+ const MessageContainer = styled . div `
350+ display: flex;
340351 flex-direction: column;
341352 height: 770px;
342353` ;
@@ -371,7 +382,7 @@ const LoadingBubble = styled.div`
371382 padding: 16px;
372383 border-radius: 8px;
373384 position: relative;
374-
385+
375386 &::after {
376387 content: '';
377388 position: absolute;
@@ -399,17 +410,19 @@ const Dot = styled.div`
399410 &:nth-child(1) {
400411 animation-delay: 0s;
401412 }
402-
413+
403414 &:nth-child(2) {
404415 animation-delay: 0.2s;
405416 }
406-
417+
407418 &:nth-child(3) {
408419 animation-delay: 0.4s;
409420 }
410421
411422 @keyframes blink {
412- 0%, 80%, 100% {
423+ 0%,
424+ 80%,
425+ 100% {
413426 opacity: 0.3;
414427 transform: scale(0.8);
415428 }
@@ -421,4 +434,3 @@ const Dot = styled.div`
421434` ;
422435
423436export default Chat ;
424-
0 commit comments