-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathChatbotPage.tsx
More file actions
110 lines (95 loc) ยท 4.24 KB
/
Copy pathChatbotPage.tsx
File metadata and controls
110 lines (95 loc) ยท 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { Logo4 } from '@shared/assets/logo';
import { ChatInput } from '@shared/ui/ChatInput';
import { useEffect, useRef, useState } from 'react';
import { ChatMessageList } from './ChatMessageList';
import type { ChatMessage } from '../model/types';
const INITIAL_BOT_MESSAGE = `๋ฃจํ์ด ์์ ์๋ฆฌ๋น๋ฅผ ๋น ๋ฅด๊ฒ ๊ณ์ฐํด๋๋ฆด๊ฒ์. ์๋ 3๊ฐ์ง๋ง ์๋ ค์ฃผ์ธ์.
(๊ฒฌ์ ์ ์ถ์ ์น์ด๋ฉฐ ์ค์ ๋น์ฉ์ ์๋ฆฌ์ /๋ถํ/์ํ์ ๋ฐ๋ผ ๋ฌ๋ผ์ง ์ ์์ด์.)
๊ธฐ์ข
: ์) ์์ดํฐ 15, ๊ฐค๋ญ์ S23
์ด๋๊ฐ ๊ณ ์ฅ๋ฌ๋์ง: ์) ์ก์ /๋ฐฐํฐ๋ฆฌ/์นด๋ฉ๋ผ/ํ๋ฉด/์ถฉ์ /์นจ์
๋ณดํ/์ผ์ด ๊ฐ์
์ฌ๋ถ: ์) ์ ํ์ผ์ด O/X, ํต์ ์ฌ ๋ณดํ O/X
๊ฐ๋ฅํ๋ฉด\u00A0์ํ๋\u00A0๋ฐฉํฅ๋\u00A0ํ\u00A0์ค๋ก\u00A0์ ์ด์ฃผ์ธ์:\u00A0โ์ ํ\u00A0์ฐ์ โ\u00A0/\u00A0โ์ต๋ํ\u00A0์ ๋ ดํ\u2060๊ฒโ\u00A0/\u00A0โ๋นจ๋ฆฌโ
์์) โ์์ดํฐ 15, ์ก์ ๊นจ์ง, ์ ํ์ผ์ด X, ์ต๋ํ ์ ๋ ดํ๊ฒโ
`;
const ChatbotPage = () => {
const [message, setMessage] = useState('');
const [messages, setMessages] = useState<ChatMessage[]>(() => [
{
id: 'bot-initial',
role: 'bot' as const,
content: INITIAL_BOT_MESSAGE,
status: 'done',
},
]);
const replyTimeoutRef = useRef<number | null>(null);
const endOfMessagesRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
return () => {
if (replyTimeoutRef.current) {
window.clearTimeout(replyTimeoutRef.current);
}
};
}, []);
useEffect(() => {
endOfMessagesRef.current?.scrollIntoView({ behavior: 'smooth', block: 'end' });
}, [messages]);
const handleSend = (value: string) => {
const trimmed = value.trim();
if (!trimmed) {
return;
}
const userId = `user-${Date.now()}`;
const botId = `bot-${Date.now()}`;
setMessages((prev) => [
...prev,
{ id: userId, role: 'user', content: trimmed, status: 'done' },
{ id: botId, role: 'bot', content: '๋ต๋ณ์ ์ค๋น ์ค์ด์์...', status: 'loading' },
]);
setMessage('');
if (replyTimeoutRef.current) {
window.clearTimeout(replyTimeoutRef.current);
}
replyTimeoutRef.current = window.setTimeout(() => {
setMessages((prev) =>
prev.map((item) =>
item.id === botId
? {
...item,
status: 'done',
content: '์
๋ ฅํ์ ๋ด์ฉ์ผ๋ก ์์ ์๋ฆฌ๋น๋ฅผ ์ค๋นํ ๊ฒ์.\nํ์ํ๋ฉด ๊ธฐ์ข
/์ฆ์ ์์ธ๋ฅผ ๋ ์๋ ค์ฃผ์ธ์!',
}
: item
)
);
}, 800);
};
return (
<div className="w-full bg-white">
<div className="mx-auto flex min-h-screen w-full max-w-[1440px] flex-col bg-white xl:min-h-[1024px]">
<main className="flex flex-1 flex-col px-[var(--margin-l)] md:px-[var(--spacing-xxxl)] xl:px-0">
<section className="mx-auto flex w-full max-w-full flex-col items-start gap-[19px] self-stretch pb-[140px] xl:max-w-[1200px]">
<div className="flex items-center gap-[var(--spacing-m)] md:gap-[var(--spacing-xl)] xl:gap-[36px]">
<div className="flex h-[64px] w-[64px] flex-shrink-0 flex-col items-center justify-center gap-[10px] rounded-full bg-black pt-[var(--padding-xl)] pr-[10px] pb-[var(--padding-xl)] pl-[14px] md:h-[72px] md:w-[72px] md:pt-[26px] md:pr-[11px] md:pb-[28px] md:pl-[15px] xl:h-[80px] xl:w-[80px] xl:pt-[31px] xl:pr-[13px] xl:pb-[33px] xl:pl-[17px]">
<Logo4 className="h-[80px] w-[80px] flex-shrink-0" aria-hidden="true" />
</div>
<h1 className="typo-title-2 text-black">๋ฃจํ๋ด</h1>
</div>
<ChatMessageList messages={messages} />
<div ref={endOfMessagesRef} className="scroll-mb-[96px]" />
</section>
<div className="fixed inset-x-0 bottom-[var(--margin-s)] z-50 px-[var(--margin-l)] md:px-[var(--spacing-xxxl)] xl:px-[120px]">
<div className="mx-auto w-full max-w-full xl:max-w-[1200px]">
<ChatInput
placeholder="๋ฌด์จ ๊ฒฌ์ ์ ์ํ์๋์?"
value={message}
onChange={setMessage}
onSend={handleSend}
/>
</div>
</div>
</main>
</div>
</div>
);
};
export default ChatbotPage;