From 0514dca47cdf16aca6f9af60ea01f07d42d99a65 Mon Sep 17 00:00:00 2001 From: Choi JunHo Date: Wed, 6 Nov 2024 00:40:12 +0900 Subject: [PATCH] refactor: custom category button fetch --- src/hooks/use-preset-button.hooks.ts | 17 ++++++++++++++--- .../user-domain/question-preset-buttons.tsx | 6 +----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/hooks/use-preset-button.hooks.ts b/src/hooks/use-preset-button.hooks.ts index 238e7ae..908bc59 100644 --- a/src/hooks/use-preset-button.hooks.ts +++ b/src/hooks/use-preset-button.hooks.ts @@ -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); @@ -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('답변 생성에 실패했습니다. 새로고침해주세요'); diff --git a/src/ui/components/user-domain/question-preset-buttons.tsx b/src/ui/components/user-domain/question-preset-buttons.tsx index 430e1ca..0edf985 100644 --- a/src/ui/components/user-domain/question-preset-buttons.tsx +++ b/src/ui/components/user-domain/question-preset-buttons.tsx @@ -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 (