index.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import copy from 'copy-to-clipboard'
  7. import NoData from './no-data'
  8. import type { SavedMessage } from '@/models/debug'
  9. import { Markdown } from '@/app/components/base/markdown'
  10. import { SimpleBtn, copyIcon } from '@/app/components/app/text-generate/item'
  11. import Toast from '@/app/components/base/toast'
  12. export type ISavedItemsProps = {
  13. className?: string
  14. list: SavedMessage[]
  15. onRemove: (id: string) => void
  16. onStartCreateContent: () => void
  17. }
  18. const removeIcon = (
  19. <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
  20. <path d="M5.25 1.75H8.75M1.75 3.5H12.25M11.0833 3.5L10.6742 9.63625C10.6129 10.5569 10.5822 11.0172 10.3833 11.3663C10.2083 11.6735 9.94422 11.9206 9.62597 12.0748C9.26448 12.25 8.80314 12.25 7.88045 12.25H6.11955C5.19686 12.25 4.73552 12.25 4.37403 12.0748C4.05577 11.9206 3.79172 11.6735 3.61666 11.3663C3.41781 11.0172 3.38713 10.5569 3.32575 9.63625L2.91667 3.5M5.83333 6.125V9.04167M8.16667 6.125V9.04167" stroke="#344054" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round" />
  21. </svg>
  22. )
  23. const SavedItems: FC<ISavedItemsProps> = ({
  24. className,
  25. list,
  26. onRemove,
  27. onStartCreateContent,
  28. }) => {
  29. const { t } = useTranslation()
  30. return (
  31. <div className={cn(className, 'space-y-3')}>
  32. {list.length === 0
  33. ? (
  34. <div className='px-6'>
  35. <NoData onStartCreateContent={onStartCreateContent} />
  36. </div>
  37. )
  38. : (<>
  39. {list.map(({ id, answer }) => (
  40. <div
  41. key={id}
  42. className='p-4 rounded-xl bg-gray-50'
  43. style={{
  44. boxShadow: '0px 1px 2px rgba(16, 24, 40, 0.05)',
  45. }}
  46. >
  47. <Markdown content={answer} />
  48. <div className='flex items-center justify-between mt-3'>
  49. <div className='flex items-center space-x-2'>
  50. <SimpleBtn
  51. className='space-x-1'
  52. onClick={() => {
  53. copy(answer)
  54. Toast.notify({ type: 'success', message: t('common.actionMsg.copySuccessfully') })
  55. }}>
  56. {copyIcon}
  57. <div>{t('common.operation.copy')}</div>
  58. </SimpleBtn>
  59. <SimpleBtn
  60. className='space-x-1'
  61. onClick={() => {
  62. onRemove(id)
  63. }}>
  64. {removeIcon}
  65. <div>{t('common.operation.remove')}</div>
  66. </SimpleBtn>
  67. </div>
  68. <div className='text-xs text-gray-500'>{answer?.length} {t('common.unit.char')}</div>
  69. </div>
  70. </div>
  71. ))}
  72. </>)}
  73. </div>
  74. )
  75. }
  76. export default React.memo(SavedItems)