@daeryun/dr_components 0.6.40 → 0.6.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asset/images/daeryuntalk/daeryuntalk-intro.png +0 -0
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/components/Daeryuntalk/ChatHomeView.jsx +5 -3
- package/dist/components/Daeryuntalk/ChatHomeView.tsx +11 -6
- package/dist/components/page/Integrate/AISearch.d.ts +6 -0
- package/dist/components/page/Integrate/AISearch.jsx +95 -0
- package/dist/components/page/Integrate/AISearch.stories.d.ts +6 -0
- package/dist/components/page/Integrate/AISearch.stories.jsx +13 -0
- package/dist/components/page/Integrate/AISearch.stories.tsx +21 -0
- package/dist/components/page/Integrate/AISearch.tsx +114 -0
- package/dist/styles/globals.css +333 -288
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { useLayoutEffect, useState, useCallback, memo } from 'react';
|
|
4
|
+
|
|
5
|
+
interface SearchProps {
|
|
6
|
+
search: string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const AnimatedTextComponent = ({ text }: { text: string }) => {
|
|
10
|
+
const [displayedText, setDisplayedText] = useState('');
|
|
11
|
+
|
|
12
|
+
const noticeText =
|
|
13
|
+
'위 답변은 임의로 제공되는 정보로서 더 알고싶은 정보에 대해 구체적으로 입력하시면 추가 정보가 제공됩니다.';
|
|
14
|
+
const finalText = `${text}\n\n${noticeText}`;
|
|
15
|
+
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
let frameId: number;
|
|
18
|
+
let index = 0;
|
|
19
|
+
|
|
20
|
+
const animate = () => {
|
|
21
|
+
if (index <= finalText.length) {
|
|
22
|
+
setDisplayedText(finalText.slice(0, index));
|
|
23
|
+
index++;
|
|
24
|
+
frameId = requestAnimationFrame(animate);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
frameId = requestAnimationFrame(animate);
|
|
29
|
+
|
|
30
|
+
return () => cancelAnimationFrame(frameId);
|
|
31
|
+
}, [finalText]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="whitespace-pre-wrap text-[16px] text-black max-sm:text-[14px]">
|
|
35
|
+
{displayedText.split('\n').map((line, index, arr) => {
|
|
36
|
+
const isNoticeLine = line.includes('위 답변은 임의로');
|
|
37
|
+
const isLast = index === arr.length - 1;
|
|
38
|
+
return (
|
|
39
|
+
<React.Fragment key={index}>
|
|
40
|
+
<span className={isNoticeLine ? 'mt-2 block font-semibold max-sm:text-[14px]' : ''}>
|
|
41
|
+
{line}
|
|
42
|
+
</span>
|
|
43
|
+
{!isLast && <br />}
|
|
44
|
+
</React.Fragment>
|
|
45
|
+
);
|
|
46
|
+
})}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const AnimatedText = memo(AnimatedTextComponent);
|
|
52
|
+
AnimatedText.displayName = 'AnimatedText';
|
|
53
|
+
|
|
54
|
+
const AiSearch = ({ search }: SearchProps) => {
|
|
55
|
+
const [responseData, setResponseData] = useState<string | null>(null);
|
|
56
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
57
|
+
|
|
58
|
+
const fetchData = useCallback(async (searchTerm: string) => {
|
|
59
|
+
setIsLoading(true);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch('https://aechvx7pyqs62dokya5auww2xa0atuqn.lambda-url.ap-northeast-2.on.aws/', {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: { 'Content-Type': 'application/json' },
|
|
65
|
+
body: JSON.stringify({ keyword: searchTerm })
|
|
66
|
+
});
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
|
|
69
|
+
if (data.status === 'SUCCEEDED' && data.output) {
|
|
70
|
+
setResponseData(data.output);
|
|
71
|
+
} else {
|
|
72
|
+
setResponseData('잘못된 응답입니다.');
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Error fetching data:', error);
|
|
76
|
+
setResponseData('데이터를 가져오는 중 오류가 발생했습니다.');
|
|
77
|
+
} finally {
|
|
78
|
+
setIsLoading(false);
|
|
79
|
+
}
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
useLayoutEffect(() => {
|
|
83
|
+
if (search) {
|
|
84
|
+
fetchData(search);
|
|
85
|
+
}
|
|
86
|
+
}, [search, fetchData]);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div className="mb-4 mt-[50px]">
|
|
90
|
+
<div className="mb-2 rounded-xl p-5 shadow-sm" style={{ border: '1px solid #CECECE' }}>
|
|
91
|
+
<h3 className="mb-4 text-xl font-semibold">
|
|
92
|
+
<span className="relative font-extrabold text-[#ab0634]">
|
|
93
|
+
AI 대륜 <span className="absolute -right-0.5 -top-3.5 text-2xl text-[#ab0634]">·</span>
|
|
94
|
+
</span>
|
|
95
|
+
이 자세히 알려드립니다.
|
|
96
|
+
</h3>
|
|
97
|
+
|
|
98
|
+
{isLoading ? (
|
|
99
|
+
<div className="relative h-2 w-full overflow-hidden rounded bg-gray-300">
|
|
100
|
+
<div className="animate-integrate_loading_bar h-full rounded bg-blue-500" />
|
|
101
|
+
</div>
|
|
102
|
+
) : responseData ? (
|
|
103
|
+
<AnimatedText text={responseData} />
|
|
104
|
+
) : null}
|
|
105
|
+
</div>
|
|
106
|
+
<p className="break-keep text-right text-sm max-xl:text-left max-md2:text-[13px]">
|
|
107
|
+
*위 답변은 인공지능이 작성한 내용으로 '정보제공을 위한 것'입니다. 위 답변에는 법적효력이
|
|
108
|
+
없으므로 참고자료로만 활용해 주시고 구체적 적용을 위해서는 변호사와 상담을 권해드립니다.
|
|
109
|
+
</p>
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default AiSearch;
|