2023-05-25 16:59:47 +08:00
|
|
|
'use client'
|
2023-06-01 23:19:36 +08:00
|
|
|
import type { FC } from 'react'
|
|
|
|
import React from 'react'
|
2023-05-25 16:59:47 +08:00
|
|
|
import cn from 'classnames'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2023-08-30 17:32:32 +08:00
|
|
|
import { Edit03, Pin02, Trash03 } from '../../base/icons/src/vender/line/general'
|
2023-05-25 16:59:47 +08:00
|
|
|
|
|
|
|
import s from './style.module.css'
|
2023-06-01 23:19:36 +08:00
|
|
|
import Popover from '@/app/components/base/popover'
|
2023-05-25 16:59:47 +08:00
|
|
|
|
2023-06-01 23:19:36 +08:00
|
|
|
export type IItemOperationProps = {
|
2023-05-25 16:59:47 +08:00
|
|
|
className?: string
|
|
|
|
isPinned: boolean
|
2023-08-30 17:32:32 +08:00
|
|
|
isShowRenameConversation?: boolean
|
|
|
|
onRenameConversation?: () => void
|
2023-05-25 16:59:47 +08:00
|
|
|
isShowDelete: boolean
|
|
|
|
togglePin: () => void
|
|
|
|
onDelete: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const ItemOperation: FC<IItemOperationProps> = ({
|
|
|
|
className,
|
|
|
|
isPinned,
|
|
|
|
togglePin,
|
2023-08-30 17:32:32 +08:00
|
|
|
isShowRenameConversation,
|
|
|
|
onRenameConversation,
|
|
|
|
isShowDelete,
|
2023-06-01 23:19:36 +08:00
|
|
|
onDelete,
|
2023-05-25 16:59:47 +08:00
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Popover
|
|
|
|
htmlContent={
|
|
|
|
<div className='w-full py-1' onClick={(e) => {
|
|
|
|
e.stopPropagation()
|
|
|
|
}}>
|
|
|
|
<div className={cn(s.actionItem, 'hover:bg-gray-50 group')} onClick={togglePin}>
|
2023-08-30 17:32:32 +08:00
|
|
|
<Pin02 className='shrink-0 w-4 h-4 text-gray-500'/>
|
2023-05-25 16:59:47 +08:00
|
|
|
<span className={s.actionName}>{isPinned ? t('explore.sidebar.action.unpin') : t('explore.sidebar.action.pin')}</span>
|
|
|
|
</div>
|
2023-08-30 17:32:32 +08:00
|
|
|
{isShowRenameConversation && (
|
|
|
|
<div className={cn(s.actionItem, 'hover:bg-gray-50 group')} onClick={onRenameConversation}>
|
|
|
|
<Edit03 className='shrink-0 w-4 h-4 text-gray-500'/>
|
|
|
|
<span className={s.actionName}>{t('explore.sidebar.action.rename')}</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-05-25 16:59:47 +08:00
|
|
|
{isShowDelete && (
|
|
|
|
<div className={cn(s.actionItem, s.deleteActionItem, 'hover:bg-gray-50 group')} onClick={onDelete} >
|
2023-08-30 17:32:32 +08:00
|
|
|
<Trash03 className={cn(s.deleteActionItemChild, 'shrink-0 w-4 h-4 stroke-current text-gray-500 stroke-2')} />
|
2023-06-29 09:24:31 +08:00
|
|
|
<span className={cn(s.actionName, s.deleteActionItemChild)}>{t('explore.sidebar.action.delete')}</span>
|
2023-06-01 23:19:36 +08:00
|
|
|
</div>
|
2023-05-25 16:59:47 +08:00
|
|
|
)}
|
2023-06-01 23:19:36 +08:00
|
|
|
|
2023-05-25 16:59:47 +08:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
trigger='click'
|
|
|
|
position='br'
|
|
|
|
btnElement={<div />}
|
2023-08-30 17:32:32 +08:00
|
|
|
btnClassName={open => cn(className, s.btn, 'h-6 w-6 rounded-md border-none py-1', open && '!bg-gray-100 !shadow-none')}
|
|
|
|
className={'!w-[120px] !px-0 h-fit !z-20'}
|
2023-05-25 16:59:47 +08:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(ItemOperation)
|