Skip to content

Commit

Permalink
(#79) 🎨 design: 챗봇 ν΄λ‘œλ°” μž…λ ₯μ‹œ λ‘œλ”© μƒνƒœ λ””μžμΈ κ΅¬ν˜„
Browse files Browse the repository at this point in the history
  • Loading branch information
inaemon committed Nov 27, 2024
1 parent 5a0abaa commit 4a7d2dd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Binary file added src/assets/gif/chatbot_loading_baseball_pink.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 26 additions & 3 deletions src/pages/Chatbot/components/input/ChatbotInputField.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React, { useState, useCallback } from "react";
import Image from "next/image";
import chatbotClickIcon from "@/src/assets/svg/chatbot_click.svg";

import FAQCategoryBar from "./FAQCategoryBar";
import FAQCategoryButton from "./FAQCategoryButton";

import ChatbotClovaLoading from "@/src/pages/Chatbot/components/loading/ChatbotClovaLoading"

// μ™ΈλΆ€ ν΄λ¦­μ‹œ λ‹«νžˆλŠ” 이벀트 ν›…
import { useOutsideClick } from "@/src/hooks/useOutsideClick";

// ν΄λ‘œλ°” API
import { handleGetClovaAnswer } from "@/src/api/ChatbotApiHandler";

interface Props {
Expand All @@ -18,8 +22,10 @@ interface Props {
const ChatbotInputField = ({isStadiumSelected, onSelect, onClovaResponseUpdate}: Props) => {
const [isFAQCategoryVisible, setIsFAQCategoryVisible] = useState(false);
const [inputClovaMessage, setInputClovaMessage] = useState(""); // ν΄λ‘œλ°”μ—κ²Œ 보낼 λ©”μ‹œμ§€
const [isLoading, setIsLoading] = useState(false); // λ‘œλ”© μƒνƒœ 관리


///////////////////////////////////////////////
////// μΉ΄ν…Œκ³ λ¦¬ κ΄€λ ¨
// FAQCategory μ»΄ν¬λ„ŒνŠΈ μ™ΈλΆ€ 클릭 μ‹œ μΉ΄ν…Œκ³ λ¦¬λ°” λ‹«κΈ°
const closeFAQCategory = () => {
setIsFAQCategoryVisible(false);
Expand All @@ -41,6 +47,9 @@ const ChatbotInputField = ({isStadiumSelected, onSelect, onClovaResponseUpdate}:
}
};


///////////////////////////////////////////////
////// ν΄λ‘œλ°” κ΄€λ ¨
// 전솑 λ²„νŠΌ ν΄λ¦­μ‹œ ν΄λ‘œλ°”μ—κ²Œ λ©”μ‹œμ§€ 전솑
const handleSendButton = useCallback(async () => {
// 빈 λ©”μ‹œμ§€μΈ 경우 μ²˜λ¦¬ν•˜μ§€ μ•ŠμŒ
Expand All @@ -50,7 +59,8 @@ const ChatbotInputField = ({isStadiumSelected, onSelect, onClovaResponseUpdate}:

// 전솑 ν›„ μž…λ ₯μ°½ λΉ„μš°κΈ° (λΉ λ₯΄κ²Œ μƒνƒœ μ—…λ°μ΄νŠΈ)
setInputClovaMessage("");

setIsLoading(true); // λ‘œλ”© μ‹œμž‘


try {
// λ©”μ‹œμ§€λ₯Ό API νŒŒλΌλ―Έν„°λ‘œ 전솑 및 응닡 λ°›κΈ°
Expand All @@ -69,10 +79,18 @@ const ChatbotInputField = ({isStadiumSelected, onSelect, onClovaResponseUpdate}:
);

} catch (error) {
//alert("API ν˜ΈμΆœμ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€.");
// λΆ€λͺ¨ μ»΄ν¬λ„ŒνŠΈμ— μ—…λ°μ΄νŠΈ
onClovaResponseUpdate(
response.answer ?? "ν΄λ‘œλ°” 닡변을 λ°›λŠ” 것에 μ‹€νŒ¨ν•˜μ˜€μŠ΅λ‹ˆλ‹€ (μ—λŸ¬λͺ…: "+error+")",
);

} finally {
setIsLoading(false); // λ‘œλ”© μ’…λ£Œ
}

}, [inputClovaMessage, onClovaResponseUpdate]);


return (
<>
{/* ν”ŒλŸ¬μŠ€ λ²„νŠΌ 리슀트 */}
Expand All @@ -97,6 +115,11 @@ const ChatbotInputField = ({isStadiumSelected, onSelect, onClovaResponseUpdate}:
<Image src={chatbotClickIcon} alt="λ©”μ‹œμ§€ 보내기 μ•„μ΄μ½˜" width={20} height={20} />
</button>
</div>

{/* λ‘œλ”© μƒνƒœμΌ λ•Œ λ Œλ”λ§ */}
{isLoading && (
<ChatbotClovaLoading/>
)}
</>
);
};
Expand Down
14 changes: 14 additions & 0 deletions src/pages/Chatbot/components/loading/ChatbotClovaLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Image from "next/image";
import chatbotLoadingAnimation from "@/src/assets/gif/chatbot_loading_baseball_pink.gif";

const ChatbotClovaLoading = () => {
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex justify-center items-center z-50">
<div className="animate-spin">
<Image src={chatbotLoadingAnimation} alt="Loading" className="w-24 h-24" />
</div>
</div>
);
};

export default ChatbotClovaLoading;

0 comments on commit 4a7d2dd

Please sign in to comment.