Skip to content

Commit 5652e32

Browse files
committed
refactor: chatMachine 불필요한 코드 수정
test를 진행하면서 chat.machine.ts에서 발견된 불필요한 코드를 제거하였습니다. issue: #19
1 parent c3a0902 commit 5652e32

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/features/chat/model/chat.machine.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ export const chatMachine = setup({
66
types: {
77
context: {} as {
88
question: Message;
9-
answer: Message;
109
messageList: MessageObj[];
11-
state: 'idle' | 'processing' | 'complete';
10+
state: 'idle' | 'processing';
1211
},
1312
events: {} as
1413
| {
1514
type: 'SUBMIT_EVENT';
1615
}
17-
| {
18-
type: 'RECEIVE_ANSWER';
19-
answer: string;
20-
}
2116
| {
2217
type: 'TYPING_QUESTION';
2318
question: string;
@@ -38,9 +33,6 @@ export const chatMachine = setup({
3833
switchStateToProcessing: assign({
3934
state: 'processing',
4035
}),
41-
switchStateToComplete: assign({
42-
state: 'complete',
43-
}),
4436
assignQuestion: assign({
4537
question: ({ event }) => {
4638
assertEvent(event, 'TYPING_QUESTION');
@@ -63,16 +55,21 @@ export const chatMachine = setup({
6355
question: '',
6456
}),
6557
assignErrorMessage: assign({
66-
answer: ({ event }) => {
67-
return '답변을 받아오는데 실패했습니다.';
58+
messageList: ({ event, context }) => {
59+
return [
60+
...context.messageList,
61+
{
62+
message: '답변을 받아오는데 실패했습니다.',
63+
isMine: false,
64+
},
65+
];
6866
},
6967
}),
7068
},
7169
}).createMachine({
7270
id: 'chatMachine',
7371
context: {
7472
question: '',
75-
answer: '',
7673
messageList: [],
7774
state: 'idle',
7875
},
@@ -102,9 +99,8 @@ export const chatMachine = setup({
10299
src: 'submitQuestion',
103100
input: ({ context }) => ({ question: context.question }),
104101
onDone: {
105-
target: 'RECEIVED ANSWER',
102+
target: 'EMPTY QUESTION FIELD',
106103
actions: [
107-
'switchStateToComplete',
108104
'resetQuestion',
109105
assign({
110106
messageList: ({ event, context }) => {
@@ -114,19 +110,14 @@ export const chatMachine = setup({
114110
];
115111
},
116112
}),
113+
'switchStateToIdle',
117114
],
118115
},
119116
onError: {
120-
target: 'RECEIVED ANSWER',
121-
actions: ['assignErrorMessage'],
117+
target: 'EMPTY QUESTION FIELD',
118+
actions: ['assignErrorMessage', 'resetQuestion', 'switchStateToIdle'],
122119
},
123120
},
124121
},
125-
'RECEIVED ANSWER': {
126-
always: {
127-
target: 'EMPTY QUESTION FIELD',
128-
actions: ['switchStateToIdle'],
129-
},
130-
},
131122
},
132123
});

src/features/chat/ui/AIChatBot/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default function AIChatBot() {
3939
handleSubmit={handleSubmitQuestion}
4040
handleInputValueChange={handleQuestionFieldChange}
4141
state={state.context.state}
42-
messageList={state.context.messageList}
4342
>
4443
{state.context.messageList.map((message, index) => {
4544
const key = `msg-${index}-${message.isMine ? 'user' : 'ai'}`;

0 commit comments

Comments
 (0)