Skip to content

Commit

Permalink
add question message copy and resend
Browse files Browse the repository at this point in the history
  • Loading branch information
hjlarry committed Sep 13, 2024
1 parent 781d294 commit 981fc3e
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 0 deletions.
46 changes: 46 additions & 0 deletions web/app/components/base/chat/chat/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)
2 changes: 2 additions & 0 deletions web/app/components/base/chat/chat/question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
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
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

0 comments on commit 981fc3e

Please sign in to comment.