Skip to content

Commit e7a4e07

Browse files
authored
Merge pull request #41 from AjouChatBot/feat/chatapi
feat: 키워드 대신 카테고리 보여주도록 수정
2 parents 93ae1a7 + 8b35e94 commit e7a4e07

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

src/components/chat/ChatInput.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const ChatInput: React.FC<ChatInputProps> = ({ mode, onSend }) => {
2727
startKeywordCollection,
2828
chatLogs,
2929
handleSend: sendMessage,
30-
keywords,
30+
category,
3131
} = useChat();
3232
const [message, setMessage] = useState('');
3333
const [isOptionsOpen, setIsOptionsOpen] = useState(false);
@@ -288,11 +288,9 @@ const ChatInput: React.FC<ChatInputProps> = ({ mode, onSend }) => {
288288
<div className='mt-2 flex items-center gap-3'>
289289
<span className='text-xs text-gray-500'>인식한 키워드</span>
290290
{message.trim().length > 0 && <TypingDots />}
291-
{keywords.length > 0 && (
291+
{category && (
292292
<div className='flex gap-2'>
293-
{keywords.map((keyword: string, index: number) => (
294-
<Tag key={index} tagtext={keyword} />
295-
))}
293+
<Tag tagtext={category} />
296294
</div>
297295
)}
298296
</div>

src/contexts/ChatContext.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export interface ChatContextType {
2121
isNewTopic?: boolean;
2222
}) => Promise<void>;
2323
clearChat: () => void;
24-
keywords: string[];
25-
setKeywords: React.Dispatch<React.SetStateAction<string[]>>;
24+
category: string;
25+
setCategory: React.Dispatch<React.SetStateAction<string>>;
2626
isNewTopic: boolean;
2727
setIsNewTopic: React.Dispatch<React.SetStateAction<boolean>>;
2828
startKeywordCollection: (message: string) => void;
@@ -35,7 +35,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
3535
}) => {
3636
const [chatLogs, setChatLogs] = useState<ChatMessage[]>([]);
3737
const [isBotTyping, setIsBotTyping] = useState(false);
38-
const [keywords, setKeywords] = useState<string[]>([]);
38+
const [category, setCategory] = useState<string>('');
3939
const [isNewTopic, setIsNewTopic] = useState(false);
4040
const currentLogsRef = useRef<ChatMessage[]>([]);
4141
const keywordIntervalRef = useRef<NodeJS.Timeout | null>(null);
@@ -66,7 +66,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
6666
}
6767

6868
const data = await response.json();
69-
setKeywords(data.keywords);
69+
setCategory(data.category);
7070
} catch (error) {
7171
console.error('Error fetching keywords:', error);
7272
}
@@ -125,7 +125,6 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
125125

126126
// Stop collecting keywords before sending message
127127
stopKeywordCollection();
128-
const finalKeywords = [...keywords];
129128

130129
const newLogs: ChatMessage[] = [
131130
...currentLogsRef.current,
@@ -154,7 +153,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
154153
user_id: user.id,
155154
message,
156155
is_new_topic: newTopic,
157-
keywords: finalKeywords,
156+
category,
158157
},
159158
accessToken,
160159
(updatedBotMessage) => {
@@ -180,8 +179,6 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
180179
)
181180
);
182181
setIsBotTyping(false);
183-
// Clear keywords for next message
184-
setKeywords([]);
185182
}
186183
);
187184
} catch (err) {
@@ -194,15 +191,14 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
194191
)
195192
);
196193
setIsBotTyping(false);
197-
setKeywords([]);
198194
}
199195
}
200196
};
201197

202198
const clearChat = () => {
203199
setChatLogs([]);
204200
currentLogsRef.current = [];
205-
setKeywords([]);
201+
setCategory('');
206202
stopKeywordCollection();
207203
};
208204

@@ -221,8 +217,8 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
221217
isBotTyping,
222218
handleSend,
223219
clearChat,
224-
keywords,
225-
setKeywords,
220+
category,
221+
setCategory,
226222
isNewTopic,
227223
setIsNewTopic,
228224
startKeywordCollection,

src/types/chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface ChatPayload {
1111
user_id: string;
1212
message: string;
1313
is_new_topic?: boolean;
14-
keywords?: string[];
14+
category?: string;
1515
}
1616

1717
export interface RecentTopic {

0 commit comments

Comments
 (0)