Skip to content

Commit

Permalink
refactor: custom category button fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
swgvenghy committed Nov 5, 2024
1 parent d69e021 commit 0514dca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/hooks/use-preset-button.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const usePresetButton = () => {
const fetchResponse = async (question: string) => {
return await postQuestion(category, type, question);
};
const customCategoryFetchResponse = async (
question: string,
customCategory: 'ADMISSION_GUIDELINE' | 'PASSING_RESULT' | 'PAST_QUESTIONS' | 'INTERVIEW_PRACTICAL_TEST',
) => {
return await postQuestion(customCategory, type, question);
};

const updateStateWithResponse = (response: any) => {
updateLastMessage(response.answer.content);
Expand All @@ -32,14 +38,19 @@ const usePresetButton = () => {
setLoading(false);
};

const handleButtonClick = async (question: string) => {
const handleButtonClick = async (question: string, category?: string) => {
try {
addMessage({ content: question, role: 'user' });
addMessage({ content: 'loading', role: 'system' });
setLoading(true);

const response = await fetchResponse(question);
updateStateWithResponse(response);
if (category === 'PASSING_RESULT' || category === 'PAST_QUESTIONS' || category === 'INTERVIEW_PRACTICAL_TEST') {
const response = await customCategoryFetchResponse(question, category);
updateStateWithResponse(response);
} else {
const response = await fetchResponse(question);
updateStateWithResponse(response);
}
} catch (error) {
setLoading(false);
updateLastMessage('답변 생성에 실패했습니다. 새로고침해주세요');
Expand Down
6 changes: 1 addition & 5 deletions src/ui/components/user-domain/question-preset-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import * as React from 'react';
import useChatStore from '../../../store/chat-store';
import PresetButton from '../atom/preset/preset-button';
import usePresetButton from '../../../hooks/use-preset-button.hooks';
import useTypeStore from '../../../store/type-category-store';

export const QuestionPresetButtons = () => {
const { lastReference, referenceButtonDisabled } = useChatStore();
const { setContentCategory } = useTypeStore();
const { handleReferenceButtonClick, handleButtonClick } = usePresetButton();
const handleReultButtonClick = (content: string) => {
setContentCategory('PASSING_RESULT');
handleButtonClick(content);
setContentCategory('ADMISSION_GUIDELINE');
handleButtonClick(content, 'PASSING_RESULT');
};

return (
Expand Down

0 comments on commit 0514dca

Please sign in to comment.