item.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useRef,
  5. } from 'react'
  6. import { useHover } from 'ahooks'
  7. import type { ConversationItem } from '@/models/share'
  8. import { MessageDotsCircle } from '@/app/components/base/icons/src/vender/solid/communication'
  9. import ItemOperation from '@/app/components/explore/item-operation'
  10. type ItemProps = {
  11. isPin?: boolean
  12. item: ConversationItem
  13. onOperate: (type: string, item: ConversationItem) => void
  14. onChangeConversation: (conversationId: string) => void
  15. currentConversationId: string
  16. }
  17. const Item: FC<ItemProps> = ({
  18. isPin,
  19. item,
  20. onOperate,
  21. onChangeConversation,
  22. currentConversationId,
  23. }) => {
  24. const ref = useRef(null)
  25. const isHovering = useHover(ref)
  26. return (
  27. <div
  28. ref={ref}
  29. key={item.id}
  30. className={`
  31. flex mb-0.5 last-of-type:mb-0 py-1.5 pl-3 pr-1.5 text-sm font-medium text-gray-700
  32. rounded-lg cursor-pointer hover:bg-gray-50 group
  33. ${currentConversationId === item.id && 'text-primary-600 bg-primary-50'}
  34. `}
  35. onClick={() => onChangeConversation(item.id)}
  36. >
  37. <MessageDotsCircle className={`shrink-0 mt-1 mr-2 w-4 h-4 text-gray-400 ${currentConversationId === item.id && 'text-primary-600'}`} />
  38. <div className='grow py-0.5 break-all' title={item.name}>{item.name}</div>
  39. {item.id !== '' && (
  40. <div className='shrink-0 h-6' onClick={e => e.stopPropagation()}>
  41. <ItemOperation
  42. isPinned={!!isPin}
  43. isItemHovering={isHovering}
  44. togglePin={() => onOperate(isPin ? 'unpin' : 'pin', item)}
  45. isShowDelete
  46. isShowRenameConversation
  47. onRenameConversation={() => onOperate('rename', item)}
  48. onDelete={() => onOperate('delete', item)}
  49. />
  50. </div>
  51. )}
  52. </div>
  53. )
  54. }
  55. export default memo(Item)