TrashItem.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import dayjs from 'dayjs';
  3. import { IconButton, ListItem } from '@mui/material';
  4. import { DeleteOutline, RestoreOutlined } from '@mui/icons-material';
  5. import { TrashPB } from '@/services/backend';
  6. import Tooltip from '@mui/material/Tooltip';
  7. import { useTranslation } from 'react-i18next';
  8. function TrashItem({
  9. item,
  10. hoverId,
  11. setHoverId,
  12. onDelete,
  13. onPutback,
  14. }: {
  15. setHoverId: (id: string) => void;
  16. item: TrashPB;
  17. hoverId: string;
  18. onPutback: (id: string) => void;
  19. onDelete: (ids: string[]) => void;
  20. }) {
  21. const { t } = useTranslation();
  22. return (
  23. <ListItem
  24. onMouseEnter={(e) => {
  25. setHoverId(item.id);
  26. }}
  27. onMouseLeave={(e) => {
  28. setHoverId('');
  29. }}
  30. key={item.id}
  31. style={{
  32. paddingInline: 0,
  33. }}
  34. >
  35. <div className={'flex w-[100%] items-center justify-around rounded-lg px-2 py-3 hover:bg-fill-list-hover'}>
  36. <div className={'w-[40%] text-left'}>{item.name}</div>
  37. <div className={'flex-1'}>{dayjs.unix(item.modified_time).format('MM/DD/YYYY hh:mm A')}</div>
  38. <div className={'flex-1'}>{dayjs.unix(item.create_time).format('MM/DD/YYYY hh:mm A')}</div>
  39. <div
  40. style={{
  41. visibility: hoverId === item.id ? 'visible' : 'hidden',
  42. }}
  43. className={'w-[64px]'}
  44. >
  45. <Tooltip placement={'top-start'} title={t('button.putback')}>
  46. <IconButton onClick={(e) => onPutback(item.id)} className={'mr-2'}>
  47. <RestoreOutlined />
  48. </IconButton>
  49. </Tooltip>
  50. <Tooltip placement={'top-start'} title={t('button.delete')}>
  51. <IconButton color={'error'} onClick={(e) => onDelete([item.id])}>
  52. <DeleteOutline />
  53. </IconButton>
  54. </Tooltip>
  55. </div>
  56. </div>
  57. </ListItem>
  58. );
  59. }
  60. export default TrashItem;