Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add copy and resend button for the question of chat #8347

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import type {
import {
memo,
} from 'react'
import type { ChatItem } from '../types'
import type { Theme } from '../embedded-chatbot/theme/theme-context'
import { CssTransform } from '../embedded-chatbot/theme/utils'
import type { ChatItem } from '../../types'
import type { Theme } from '../../embedded-chatbot/theme/theme-context'
import { CssTransform } from '../../embedded-chatbot/theme/utils'
import Operation from './operation'
import { QuestionTriangle } from '@/app/components/base/icons/src/vender/solid/general'
import { User } from '@/app/components/base/icons/src/public/avatar'
import { Markdown } from '@/app/components/base/markdown'
Expand Down Expand Up @@ -40,6 +41,7 @@ const Question: FC<QuestionProps> = ({
className='px-4 py-3 bg-[#D1E9FF]/50 rounded-b-2xl rounded-tl-2xl text-sm text-gray-900'
style={theme?.chatBubbleColorStyle ? CssTransform(theme.chatBubbleColorStyle) : {}}
>
<Operation item={item}/>
{
!!imgSrcs.length && (
<ImageGallery srcs={imgSrcs} />
Expand Down
46 changes: 46 additions & 0 deletions web/app/components/base/chat/chat/question/operation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { FC } from 'react'
import {
memo,
} from 'react'
import type { ChatItem } from '../../types'
import cn from '@/utils/classnames'
import CopyBtn from '@/app/components/base/copy-btn'
import ResendBtn from '@/app/components/base/resend-btn'

type OperationProps = {
item: ChatItem
}
const Operation: FC<OperationProps> = ({
item,
}) => {
const {
isOpeningStatement,
content,
message_files,
} = item

return (
<>
<div
className={cn('absolute flex justify-end gap-1 -top-3.5 right-0')}
>
{!isOpeningStatement && (
<div className='hidden group-hover:flex items-center w-max h-[28px] p-0.5 rounded-lg bg-white border-[0.5px] border-gray-100 shadow-md shrink-0'>
<CopyBtn
value={content}
className='hidden group-hover:block'
/>
<ResendBtn
value={content}
files={message_files}
className='hidden group-hover:block'
/>
</div>
)}

</div>
</>
)
}

export default memo(Operation)
44 changes: 44 additions & 0 deletions web/app/components/base/resend-btn/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use client'
import { t } from 'i18next'
import s from './style.module.css'
import { useChatContext } from '@/app/components/base/chat/chat/context'
import Tooltip from '@/app/components/base/tooltip'
import type { VisionFile } from '@/types/app'

type ResendBtnProps = {
value: string
files?: VisionFile[]
className?: string
isPlain?: boolean
}

const ResendBtn = ({
value,
files,
className,
isPlain,
}: ResendBtnProps) => {
const { onSend } = useChatContext()
return (
<div className={`${className}`}>
<Tooltip popupContent={t('appApi.resend')}>
<div
className={'box-border p-0.5 flex items-center justify-center rounded-md bg-white cursor-pointer'}
style={!isPlain
? {
boxShadow: '0px 4px 8px -2px rgba(16, 24, 40, 0.1), 0px 2px 4px -2px rgba(16, 24, 40, 0.06)',
}
: {}}
onClick={() => {
if (onSend)
onSend(value, files)
}}
>
<div className={`w-6 h-6 rounded-md hover:bg-gray-50 ${s.resendIcon}`}></div>
</div>
</Tooltip>
</div>
)
}

export default ResendBtn
11 changes: 11 additions & 0 deletions web/app/components/base/resend-btn/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.resendIcon {
background-image: url(~@/app/components/develop/secret-key/assets/resend.svg);
background-position: center;
background-repeat: no-repeat;
}

.resendIcon:hover {
background-image: url(~@/app/components/develop/secret-key/assets/resend-hover.svg);
background-position: center;
background-repeat: no-repeat;
}
9 changes: 9 additions & 0 deletions web/app/components/develop/secret-key/assets/resend-hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions web/app/components/develop/secret-key/assets/resend.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions web/i18n/en-US/app-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const translation = {
ok: 'In Service',
copy: 'Copy',
copied: 'Copied',
resend: 'Resend',
play: 'Play',
pause: 'Pause',
playing: 'Playing',
Expand Down
1 change: 1 addition & 0 deletions web/i18n/zh-Hans/app-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const translation = {
ok: '运行中',
copy: '复制',
copied: '已复制',
resend: '重新发送',
play: '播放',
pause: '暂停',
playing: '播放中',
Expand Down