MessageActions.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React from 'react';
  2. import {
  3. Button,
  4. Tooltip,
  5. } from '@douyinfe/semi-ui';
  6. import {
  7. RefreshCw,
  8. Copy,
  9. Trash2,
  10. } from 'lucide-react';
  11. import { useTranslation } from 'react-i18next';
  12. const MessageActions = ({ message, styleState, onMessageReset, onMessageCopy, onMessageDelete, isAnyMessageGenerating = false }) => {
  13. const { t } = useTranslation();
  14. const isLoading = message.status === 'loading' || message.status === 'incomplete';
  15. const shouldDisableActions = isAnyMessageGenerating;
  16. return (
  17. <div className="flex items-center gap-0.5">
  18. {!isLoading && (
  19. <Tooltip content={shouldDisableActions ? t('正在生成中,请稍候...') : t('重试')} position="top">
  20. <Button
  21. theme="borderless"
  22. type="tertiary"
  23. size="small"
  24. icon={<RefreshCw size={styleState.isMobile ? 12 : 14} />}
  25. onClick={() => !shouldDisableActions && onMessageReset(message)}
  26. disabled={shouldDisableActions}
  27. className={`!rounded-md ${shouldDisableActions ? '!text-gray-300 !cursor-not-allowed' : '!text-gray-400 hover:!text-blue-600 hover:!bg-blue-50'} ${styleState.isMobile ? '!w-6 !h-6' : '!w-7 !h-7'} !p-0 transition-all`}
  28. aria-label={t('重试')}
  29. />
  30. </Tooltip>
  31. )}
  32. {message.content && (
  33. <Tooltip content={t('复制')} position="top">
  34. <Button
  35. theme="borderless"
  36. type="tertiary"
  37. size="small"
  38. icon={<Copy size={styleState.isMobile ? 12 : 14} />}
  39. onClick={() => onMessageCopy(message)}
  40. className={`!rounded-md !text-gray-400 hover:!text-green-600 hover:!bg-green-50 ${styleState.isMobile ? '!w-6 !h-6' : '!w-7 !h-7'} !p-0 transition-all`}
  41. aria-label={t('复制')}
  42. />
  43. </Tooltip>
  44. )}
  45. {!isLoading && (
  46. <Tooltip content={shouldDisableActions ? t('正在生成中,请稍候...') : t('删除')} position="top">
  47. <Button
  48. theme="borderless"
  49. type="tertiary"
  50. size="small"
  51. icon={<Trash2 size={styleState.isMobile ? 12 : 14} />}
  52. onClick={() => !shouldDisableActions && onMessageDelete(message)}
  53. disabled={shouldDisableActions}
  54. className={`!rounded-md ${shouldDisableActions ? '!text-gray-300 !cursor-not-allowed' : '!text-gray-400 hover:!text-red-600 hover:!bg-red-50'} ${styleState.isMobile ? '!w-6 !h-6' : '!w-7 !h-7'} !p-0 transition-all`}
  55. aria-label={t('删除')}
  56. />
  57. </Tooltip>
  58. )}
  59. </div>
  60. );
  61. };
  62. export default MessageActions;