file-tree-toolbar.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { useTranslation } from 'react-i18next'
  2. import Icon from '../../../shared/components/icon'
  3. import TooltipButton from '../../../shared/components/tooltip-button'
  4. import { useFileTreeMainContext } from '../contexts/file-tree-main'
  5. import { useFileTreeActionable } from '../contexts/file-tree-actionable'
  6. function FileTreeToolbar() {
  7. const { hasWritePermissions } = useFileTreeMainContext()
  8. if (!hasWritePermissions) return null
  9. return (
  10. <div className="toolbar toolbar-filetree">
  11. <FileTreeToolbarLeft />
  12. <FileTreeToolbarRight />
  13. </div>
  14. )
  15. }
  16. function FileTreeToolbarLeft() {
  17. const { t } = useTranslation()
  18. const {
  19. canCreate,
  20. startCreatingFolder,
  21. startCreatingDocOrFile,
  22. startUploadingDocOrFile,
  23. } = useFileTreeActionable()
  24. if (!canCreate) return null
  25. return (
  26. <div className="toolbar-left">
  27. <TooltipButton
  28. id="new_file"
  29. description={t('new_file')}
  30. onClick={startCreatingDocOrFile}
  31. >
  32. <Icon type="file" modifier="fw" accessibilityLabel={t('new_file')} />
  33. </TooltipButton>
  34. <TooltipButton
  35. id="new_folder"
  36. description={t('new_folder')}
  37. onClick={startCreatingFolder}
  38. >
  39. <Icon
  40. type="folder"
  41. modifier="fw"
  42. accessibilityLabel={t('new_folder')}
  43. />
  44. </TooltipButton>
  45. <TooltipButton
  46. id="upload"
  47. description={t('upload')}
  48. onClick={startUploadingDocOrFile}
  49. >
  50. <Icon type="upload" modifier="fw" accessibilityLabel={t('upload')} />
  51. </TooltipButton>
  52. </div>
  53. )
  54. }
  55. function FileTreeToolbarRight() {
  56. const { t } = useTranslation()
  57. const {
  58. canRename,
  59. canDelete,
  60. startRenaming,
  61. startDeleting,
  62. } = useFileTreeActionable()
  63. if (!canRename && !canDelete) {
  64. return null
  65. }
  66. return (
  67. <div className="toolbar-right">
  68. {canRename ? (
  69. <TooltipButton
  70. id="rename"
  71. description={t('rename')}
  72. onClick={startRenaming}
  73. >
  74. <Icon type="pencil" modifier="fw" accessibilityLabel={t('rename')} />
  75. </TooltipButton>
  76. ) : null}
  77. {canDelete ? (
  78. <TooltipButton
  79. id="delete"
  80. description={t('delete')}
  81. onClick={startDeleting}
  82. >
  83. <Icon type="trash-o" modifier="fw" accessibilityLabel={t('delete')} />
  84. </TooltipButton>
  85. ) : null}
  86. </div>
  87. )
  88. }
  89. export default FileTreeToolbar