-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from MARU-EGG/TSK-41
[TSK-41] preset button setting
- Loading branch information
Showing
7 changed files
with
103 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import useChatStore, { referenceState } from '../store/chat-store'; | ||
import useTypeStore from '../store/type-category-store'; | ||
import { postQuestion } from '../api/post-question'; | ||
|
||
const usePresetButton = () => { | ||
const { type, category } = useTypeStore(); | ||
const { addMessage, setLoading, updateLastMessage, updateLastReference, updateReferenceDisabled } = useChatStore(); | ||
|
||
const handleReferenceButtonClick = (references: referenceState[]) => { | ||
let content = '답변 출처를 알려드릴게요!\n'; | ||
if (references === undefined || references.length === 0) { | ||
addMessage({ content: '출처 정보가 없습니다.', role: 'system' }); | ||
return; | ||
} | ||
references.map((reference, index) => { | ||
content += `\n출처${index + 1}번: ${reference.link}\n`; | ||
}); | ||
content += '\n**답변을 꼭 확인해주세요!**'; | ||
addMessage({ content: content, role: 'system' }); | ||
updateReferenceDisabled(true); | ||
}; | ||
|
||
const fetchResponse = async (question: string) => { | ||
return await postQuestion(category, type, question); | ||
}; | ||
|
||
const updateStateWithResponse = (response: any) => { | ||
updateLastMessage(response.answer.content); | ||
updateLastReference(response.references); | ||
updateReferenceDisabled(false); | ||
setLoading(false); | ||
}; | ||
|
||
const handleButtonClick = async (question: string) => { | ||
try { | ||
addMessage({ content: question, role: 'user' }); | ||
addMessage({ content: 'loading', role: 'system' }); | ||
setLoading(true); | ||
|
||
const response = await fetchResponse(question); | ||
updateStateWithResponse(response); | ||
} catch (error) { | ||
setLoading(false); | ||
updateLastMessage('답변 생성에 실패했습니다. 새로고침해주세요'); | ||
} | ||
}; | ||
|
||
return { | ||
handleReferenceButtonClick, | ||
handleButtonClick, | ||
}; | ||
}; | ||
|
||
export default usePresetButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import * as React from 'react'; | ||
import useChatStore from '../../../store/chat-store'; | ||
import PresetButton from '../atom/preset/preset-button'; | ||
import useChatSection from '../../../hooks/use-chat-section.hooks'; | ||
import usePresetButton from '../../../hooks/use-preset-button.hooks'; | ||
|
||
export const QuestionPresetButtons = () => { | ||
const { lastReference } = useChatStore(); | ||
const { handleReferenceButtonClick } = useChatSection(); | ||
const { lastReference, referenceButtonDisabled } = useChatStore(); | ||
const { handleReferenceButtonClick, handleButtonClick } = usePresetButton(); | ||
|
||
return ( | ||
<div> | ||
<PresetButton onClick={() => handleReferenceButtonClick(lastReference)}>답변출처확인</PresetButton> | ||
{!referenceButtonDisabled && ( | ||
<PresetButton onClick={() => handleReferenceButtonClick(lastReference)}>👆 출처를 알고싶어요</PresetButton> | ||
)} | ||
<PresetButton onClick={() => handleButtonClick('전형일정')}>전형일정</PresetButton> | ||
<PresetButton onClick={() => handleButtonClick('면접 유의사항')}>면접유의사항</PresetButton> | ||
<PresetButton onClick={() => handleButtonClick('제출서류 유의사항')}>제출서류</PresetButton> | ||
<PresetButton onClick={() => handleButtonClick('입시결과안내')}>입시결과</PresetButton> | ||
<PresetButton onClick={() => handleButtonClick('실기고사')}>실기고사</PresetButton> | ||
<PresetButton onClick={() => window.location.reload()}>조건 재설정</PresetButton> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters