header.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/app/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='flex items-center !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. selector="undo-feedback-like"
  43. content="Undo Great Rating"
  44. >
  45. <div
  46. onClick={() => {
  47. onFeedback({
  48. rating: null,
  49. })
  50. }}
  51. 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'>
  52. <HandThumbUpIcon width={16} height={16} />
  53. </div>
  54. </Tooltip>
  55. )}
  56. {showFeedback && feedback.rating && feedback.rating === 'dislike' && (
  57. <Tooltip
  58. selector="undo-feedback-dislike"
  59. content="Undo Undesirable Response"
  60. >
  61. <div
  62. onClick={() => {
  63. onFeedback({
  64. rating: null,
  65. })
  66. }}
  67. 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'>
  68. <HandThumbDownIcon width={16} height={16} />
  69. </div>
  70. </Tooltip>
  71. )}
  72. {showFeedback && !feedback.rating && (
  73. <div className='flex rounded-lg border border-gray-200 p-[1px] space-x-1'>
  74. <Tooltip
  75. selector="feedback-like"
  76. content="Great Rating"
  77. >
  78. <div
  79. onClick={() => {
  80. onFeedback({
  81. rating: 'like',
  82. })
  83. }}
  84. className='flex w-6 h-6 items-center justify-center rounded-md cursor-pointer hover:bg-gray-100'>
  85. <HandThumbUpIcon width={16} height={16} />
  86. </div>
  87. </Tooltip>
  88. <Tooltip
  89. selector="feedback-dislike"
  90. content="Undesirable Response"
  91. >
  92. <div
  93. onClick={() => {
  94. onFeedback({
  95. rating: 'dislike',
  96. })
  97. }}
  98. className='flex w-6 h-6 items-center justify-center rounded-md cursor-pointer hover:bg-gray-100'>
  99. <HandThumbDownIcon width={16} height={16} />
  100. </div>
  101. </Tooltip>
  102. </div>
  103. )}
  104. </div>
  105. </div>
  106. )
  107. }
  108. export default React.memo(Header)