@@ -14,40 +14,49 @@ import { useEffect } from "react";
14
14
import { css } from "styled-components" ;
15
15
import { useStickToBottom } from "use-stick-to-bottom" ;
16
16
import { SendChatMessageRequest } from "../apis/sendChatMessage" ;
17
+ import { useAcceptRejectButtonDisplayContext } from "../hooks/useAcceptRejectButtonDisplayStore" ;
17
18
import { useSendChatMessage } from "../hooks/useSendChatMessage" ;
18
19
import { useTarotCardDeckDisplayContext } from "../hooks/useTarotCardDeckDisplayStore" ;
19
20
import { useTextFieldInChatDisplayContext } from "../hooks/useTextFieldInChatDisplayStore" ;
20
21
import ChatCardSelect from "./ChatCardSelect" ;
21
22
import ChatHeader from "./ChatHeader" ;
23
+
22
24
export default function ChatRoom ( ) {
23
25
const { chatId } = useParams < { chatId : string } > ( ) ;
24
26
const searchParams = useSearchParams ( ) ;
25
27
const initialMessage = searchParams . get ( "message" ) ;
26
28
const { data } = useChatMessages ( Number ( chatId ) ) ;
27
- const { scrollRef, contentRef } = useStickToBottom ( ) ;
29
+ const { scrollRef, contentRef } = useStickToBottom ( {
30
+ initial : "instant" ,
31
+ resize : "instant" ,
32
+ } ) ;
33
+
28
34
const {
29
35
copyServerState,
30
36
state : messages ,
31
37
addMessage,
32
38
editMessage,
33
39
deleteMessage,
34
40
} = useChatMessagesContext ( ) ;
35
- const { isVisible : isTarotCardDeckVisible } = useTarotCardDeckDisplayContext ( ) ;
41
+ const { isVisible : isTarotCardDeckVisible , show : showTarotCardDeck } =
42
+ useTarotCardDeckDisplayContext ( ) ;
36
43
const {
37
44
isVisible : isTextFieldVisible ,
38
45
enable : enableTextField ,
39
46
disable : disableTextField ,
40
47
focus : focusTextField ,
48
+ hide : hideTextField ,
41
49
} = useTextFieldInChatDisplayContext ( ) ;
42
50
const { mutate : sendChatMessage } = useSendChatMessage ( ) ;
43
51
const pathname = usePathname ( ) ;
44
52
const router = useRouter ( ) ;
53
+ const { show : showAcceptRejectButtons } = useAcceptRejectButtonDisplayContext ( ) ;
45
54
46
55
useEffect ( ( ) => {
47
56
if ( ! data ) return ;
48
57
copyServerState ( data . messages ) ;
49
58
if ( ! initialMessage ) return ;
50
- console . log ( initialMessage ) ;
59
+
51
60
router . replace ( pathname ) ;
52
61
const message = JSON . parse ( initialMessage ) as SendChatMessageRequest ;
53
62
@@ -72,7 +81,6 @@ export default function ChatRoom() {
72
81
73
82
sendChatMessage ( JSON . parse ( initialMessage ) , {
74
83
onSuccess : async ( data ) => {
75
- console . log ( data ) ;
76
84
deleteMessage ( loadingMessageId ) ;
77
85
78
86
addMessage ( {
@@ -114,6 +122,20 @@ export default function ChatRoom() {
114
122
} ) ;
115
123
} , [ data ] ) ;
116
124
125
+ if (
126
+ ! isTarotCardDeckVisible &&
127
+ messages . length > 0 &&
128
+ messages [ messages . length - 1 ] . type === "SYSTEM_TAROT_QUESTION_ACCEPTANCE_REPLY"
129
+ ) {
130
+ hideTextField ( ) ;
131
+ showTarotCardDeck ( ) ;
132
+ }
133
+
134
+ if ( messages . length > 0 && messages [ messages . length - 1 ] . type === "SYSTEM_TAROT_QUESTION_REPLY" ) {
135
+ disableTextField ( ) ;
136
+ showAcceptRejectButtons ( ) ;
137
+ }
138
+
117
139
if ( ! chatId ) throw new Error ( "chatId가 Dynamic Route에서 전달 되어야 합니다." ) ;
118
140
if ( ! data ) return null ;
119
141
@@ -160,9 +182,8 @@ export default function ChatRoom() {
160
182
/>
161
183
) ;
162
184
} ) }
185
+ < AcceptRejectButtons />
163
186
</ div >
164
-
165
- < AcceptRejectButtons />
166
187
</ div >
167
188
{ isTarotCardDeckVisible && < ChatCardSelect /> }
168
189
{ isTextFieldVisible && (
0 commit comments