From 74d954610f7fc4c0b3807af1119384af091b663e Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 17 May 2023 11:22:25 +0800 Subject: [PATCH] Feat/support copy apikey and chat message (#62) --- .../components/app/chat/copy-btn/index.tsx | 44 +++++++++++++++++++ .../app/chat/copy-btn/style.module.css | 15 +++++++ web/app/components/app/chat/index.tsx | 5 +++ web/app/components/app/chat/style.module.css | 8 ++++ .../app/overview/customize/index.tsx | 2 +- 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 web/app/components/app/chat/copy-btn/index.tsx create mode 100644 web/app/components/app/chat/copy-btn/style.module.css diff --git a/web/app/components/app/chat/copy-btn/index.tsx b/web/app/components/app/chat/copy-btn/index.tsx new file mode 100644 index 0000000000..f384e714d5 --- /dev/null +++ b/web/app/components/app/chat/copy-btn/index.tsx @@ -0,0 +1,44 @@ +'use client' +import React from 'react' +import Tooltip from '@/app/components/base/tooltip' +import { t } from 'i18next' +import s from './style.module.css' +import copy from 'copy-to-clipboard' + + +type ICopyBtnProps = { + value: string + className?: string +} + +const CopyBtn = ({ + value, + className, +}: ICopyBtnProps) => { + const [isCopied, setIsCopied] = React.useState(false) + + return ( +
+ +
{ + copy(value) + setIsCopied(true) + }} + > +
+
+
+
+ ) +} + +export default CopyBtn diff --git a/web/app/components/app/chat/copy-btn/style.module.css b/web/app/components/app/chat/copy-btn/style.module.css new file mode 100644 index 0000000000..56c756025b --- /dev/null +++ b/web/app/components/app/chat/copy-btn/style.module.css @@ -0,0 +1,15 @@ +.copyIcon { + background-image: url(~@/app/components/develop/secret-key/assets/copy.svg); + background-position: center; + background-repeat: no-repeat; +} + +.copyIcon:hover { + background-image: url(~@/app/components/develop/secret-key/assets/copy-hover.svg); + background-position: center; + background-repeat: no-repeat; +} + +.copyIcon.copied { + background-image: url(~@/app/components/develop/secret-key/assets/copied.svg); +} \ No newline at end of file diff --git a/web/app/components/app/chat/index.tsx b/web/app/components/app/chat/index.tsx index 577f0b1c1b..38d85edc4c 100644 --- a/web/app/components/app/chat/index.tsx +++ b/web/app/components/app/chat/index.tsx @@ -17,6 +17,7 @@ import AppContext from '@/context/app-context' import { Markdown } from '@/app/components/base/markdown' import LoadingAnim from './loading-anim' import { formatNumber } from '@/utils/format' +import CopyBtn from './copy-btn' const stopIcon = ( @@ -346,6 +347,10 @@ const Answer: FC = ({ item, feedbackDisabled = false, isHideFeedba }
+ {!feedbackDisabled && !item.feedbackDisabled && renderItemOperation(displayScene !== 'console')} {/* Admin feedback is displayed only in the background. */} {!feedbackDisabled && renderFeedbackRating(localAdminFeedback?.rating, false, false)} diff --git a/web/app/components/app/chat/style.module.css b/web/app/components/app/chat/style.module.css index 0744311c6d..68e3f100d4 100644 --- a/web/app/components/app/chat/style.module.css +++ b/web/app/components/app/chat/style.module.css @@ -38,6 +38,14 @@ background: url(./icons/answer.svg) no-repeat; } +.copyBtn { + display: none; +} + +.answerWrap:hover .copyBtn { + display: block; +} + .answerWrap .itemOperation { display: none; } diff --git a/web/app/components/app/overview/customize/index.tsx b/web/app/components/app/overview/customize/index.tsx index a1d46ff0b2..0612c952c9 100644 --- a/web/app/components/app/overview/customize/index.tsx +++ b/web/app/components/app/overview/customize/index.tsx @@ -71,7 +71,7 @@ const CustomizeModal: FC = ({
{t(`${prefixCustomize}.way1.step2`)}
{t(`${prefixCustomize}.way1.step2Tip`)}
-
+          
             export const APP_ID = '{appId}'
export const API_KEY = {`''`}