您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

group-button.tsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import CopyToClipboard from '@/components/copy-to-clipboard';
  2. import { useSetModalState } from '@/hooks/common-hooks';
  3. import { IRemoveMessageById } from '@/hooks/logic-hooks';
  4. import {
  5. DeleteOutlined,
  6. DislikeOutlined,
  7. LikeOutlined,
  8. SoundOutlined,
  9. SyncOutlined,
  10. } from '@ant-design/icons';
  11. import { Radio, Tooltip } from 'antd';
  12. import { useCallback } from 'react';
  13. import { useTranslation } from 'react-i18next';
  14. import SvgIcon from '../svg-icon';
  15. import FeedbackModal from './feedback-modal';
  16. import { useRemoveMessage, useSendFeedback } from './hooks';
  17. import PromptModal from './prompt-modal';
  18. interface IProps {
  19. messageId: string;
  20. content: string;
  21. prompt?: string;
  22. }
  23. export const AssistantGroupButton = ({
  24. messageId,
  25. content,
  26. prompt,
  27. }: IProps) => {
  28. const { visible, hideModal, showModal, onFeedbackOk, loading } =
  29. useSendFeedback(messageId);
  30. const {
  31. visible: promptVisible,
  32. hideModal: hidePromptModal,
  33. showModal: showPromptModal,
  34. } = useSetModalState();
  35. const { t } = useTranslation();
  36. const handleLike = useCallback(() => {
  37. onFeedbackOk({ thumbup: true });
  38. }, [onFeedbackOk]);
  39. return (
  40. <>
  41. <Radio.Group size="small">
  42. <Radio.Button value="a">
  43. <CopyToClipboard text={content}></CopyToClipboard>
  44. </Radio.Button>
  45. <Radio.Button value="b">
  46. <Tooltip title={t('chat.read')}>
  47. <SoundOutlined />
  48. </Tooltip>
  49. </Radio.Button>
  50. <Radio.Button value="c" onClick={handleLike}>
  51. <LikeOutlined />
  52. </Radio.Button>
  53. <Radio.Button value="d" onClick={showModal}>
  54. <DislikeOutlined />
  55. </Radio.Button>
  56. {prompt && (
  57. <Radio.Button value="e" onClick={showPromptModal}>
  58. <SvgIcon name={`prompt`} width={16}></SvgIcon>
  59. </Radio.Button>
  60. )}
  61. </Radio.Group>
  62. {visible && (
  63. <FeedbackModal
  64. visible={visible}
  65. hideModal={hideModal}
  66. onOk={onFeedbackOk}
  67. loading={loading}
  68. ></FeedbackModal>
  69. )}
  70. {promptVisible && (
  71. <PromptModal
  72. visible={promptVisible}
  73. hideModal={hidePromptModal}
  74. prompt={prompt}
  75. ></PromptModal>
  76. )}
  77. </>
  78. );
  79. };
  80. interface UserGroupButtonProps extends IRemoveMessageById {
  81. messageId: string;
  82. content: string;
  83. regenerateMessage(): void;
  84. sendLoading: boolean;
  85. }
  86. export const UserGroupButton = ({
  87. content,
  88. messageId,
  89. sendLoading,
  90. removeMessageById,
  91. regenerateMessage,
  92. }: UserGroupButtonProps) => {
  93. const { onRemoveMessage, loading } = useRemoveMessage(
  94. messageId,
  95. removeMessageById,
  96. );
  97. const { t } = useTranslation();
  98. return (
  99. <Radio.Group size="small">
  100. <Radio.Button value="a">
  101. <CopyToClipboard text={content}></CopyToClipboard>
  102. </Radio.Button>
  103. <Radio.Button
  104. value="b"
  105. onClick={regenerateMessage}
  106. disabled={sendLoading}
  107. >
  108. <Tooltip title={t('chat.regenerate')}>
  109. <SyncOutlined spin={sendLoading} />
  110. </Tooltip>
  111. </Radio.Button>
  112. <Radio.Button value="c" onClick={onRemoveMessage} disabled={loading}>
  113. <Tooltip title={t('common.delete')}>
  114. <DeleteOutlined spin={loading} />
  115. </Tooltip>
  116. </Radio.Button>
  117. </Radio.Group>
  118. );
  119. };