header.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { ClipboardDocumentIcon, HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline'
  6. import copy from 'copy-to-clipboard'
  7. import type { FeedbackType } from '@/app/components/base/chat/chat/type'
  8. import Button from '@/app/components/base/button'
  9. import Toast from '@/app/components/base/toast'
  10. import Tooltip from '@/app/components/base/tooltip'
  11. type IResultHeaderProps = {
  12. result: string
  13. showFeedback: boolean
  14. feedback: FeedbackType
  15. onFeedback: (feedback: FeedbackType) => void
  16. }
  17. const Header: FC<IResultHeaderProps> = ({
  18. feedback,
  19. showFeedback,
  20. onFeedback,
  21. result,
  22. }) => {
  23. const { t } = useTranslation()
  24. return (
  25. <div className='flex w-full justify-between items-center '>
  26. <div className='text-gray-800 text-2xl leading-4 font-normal'>{t('share.generation.resultTitle')}</div>
  27. <div className='flex items-center space-x-2'>
  28. <Button
  29. className='h-7 p-[2px] pr-2'
  30. onClick={() => {
  31. copy(result)
  32. Toast.notify({ type: 'success', message: 'copied' })
  33. }}
  34. >
  35. <>
  36. <ClipboardDocumentIcon className='text-gray-500 w-4 h-3 mr-1' />
  37. <span className='text-gray-500 text-xs leading-3'>{t('share.generation.copy')}</span>
  38. </>
  39. </Button>
  40. {showFeedback && feedback.rating && feedback.rating === 'like' && (
  41. <Tooltip
  42. popupContent="Undo Great Rating"
  43. >
  44. <div
  45. onClick={() => {
  46. onFeedback({
  47. rating: null,
  48. })
  49. }}
  50. className='flex w-7 h-7 items-center justify-center rounded-md cursor-pointer !text-primary-600 border border-primary-200 bg-primary-100 hover:border-primary-300 hover:bg-primary-200'>
  51. <HandThumbUpIcon width={16} height={16} />
  52. </div>
  53. </Tooltip>
  54. )}
  55. {showFeedback && feedback.rating && feedback.rating === 'dislike' && (
  56. <Tooltip
  57. popupContent="Undo Undesirable Response"
  58. >
  59. <div
  60. onClick={() => {
  61. onFeedback({
  62. rating: null,
  63. })
  64. }}
  65. className='flex w-7 h-7 items-center justify-center rounded-md cursor-pointer !text-red-600 border border-red-200 bg-red-100 hover:border-red-300 hover:bg-red-200'>
  66. <HandThumbDownIcon width={16} height={16} />
  67. </div>
  68. </Tooltip>
  69. )}
  70. {showFeedback && !feedback.rating && (
  71. <div className='flex rounded-lg border border-gray-200 p-[1px] space-x-1'>
  72. <Tooltip
  73. popupContent="Great Rating"
  74. needsDelay={false}
  75. >
  76. <div
  77. onClick={() => {
  78. onFeedback({
  79. rating: 'like',
  80. })
  81. }}
  82. className='flex w-6 h-6 items-center justify-center rounded-md cursor-pointer hover:bg-gray-100'>
  83. <HandThumbUpIcon width={16} height={16} />
  84. </div>
  85. </Tooltip>
  86. <Tooltip
  87. popupContent="Undesirable Response"
  88. needsDelay={false}
  89. >
  90. <div
  91. onClick={() => {
  92. onFeedback({
  93. rating: 'dislike',
  94. })
  95. }}
  96. className='flex w-6 h-6 items-center justify-center rounded-md cursor-pointer hover:bg-gray-100'>
  97. <HandThumbDownIcon width={16} height={16} />
  98. </div>
  99. </Tooltip>
  100. </div>
  101. )}
  102. </div>
  103. </div>
  104. )
  105. }
  106. export default React.memo(Header)