-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Frontend refactor: extracted drive item icon into own component
- Loading branch information
1 parent
579b649
commit 430c7e8
Showing
3 changed files
with
58 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
tdrive/frontend/src/app/views/client/body/drive/documents/document-icon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Avatar from '../../../../../atoms/avatar'; | ||
import { | ||
FileTypeArchiveIcon, | ||
FileTypeDocumentIcon, | ||
FileTypeLinkIcon, | ||
FileTypeMediaIcon, | ||
FileTypePdfIcon, | ||
FileTypeSlidesIcon, | ||
FileTypeSpreadsheetIcon, | ||
FileTypeUnknownIcon, | ||
} from '@atoms/icons-colored'; | ||
import { FolderIcon } from '@heroicons/react/solid'; | ||
import fileUploadApiClient from '@features/files/api/file-upload-api-client'; | ||
import type { DriveItem, FileMetadata } from 'app/features/drive/types'; | ||
|
||
export const DocumentIcon = (props: { | ||
item?: DriveItem; | ||
className?: string; | ||
fileType?: string; | ||
blueiffyFolders?: boolean; | ||
}) => { | ||
const fileType = props.fileType || fileUploadApiClient.mimeToType( | ||
props.item?.last_version_cache?.file_metadata?.mime || '', | ||
); | ||
const metadata = (props.item?.last_version_cache?.file_metadata || {}) as FileMetadata; | ||
const className = props.className || 'h-5 w-5 shrink-0 text-gray-400'; | ||
return (metadata.thumbnails?.length || 0) > 0 ? ( | ||
<Avatar | ||
className={props.className} | ||
avatar={metadata.thumbnails?.[0]?.url} | ||
size="xs" | ||
type="square" | ||
title={metadata.name} | ||
/> | ||
) : props.item?.is_directory ? ( | ||
<FolderIcon className={className + (props.blueiffyFolders || props.blueiffyFolders == null ? ' text-blue-500' : '')} /> | ||
) : fileType === 'image' || fileType === 'video' ? ( | ||
<FileTypeMediaIcon className={className} /> | ||
) : fileType === 'archive' ? ( | ||
<FileTypeArchiveIcon className={className} /> | ||
) : fileType === 'pdf' ? ( | ||
<FileTypePdfIcon className={className} /> | ||
) : fileType === 'document' ? ( | ||
<FileTypeDocumentIcon className={className} /> | ||
) : fileType === 'spreadsheet' ? ( | ||
<FileTypeSpreadsheetIcon className={className} /> | ||
) : fileType === 'slides' ? ( | ||
<FileTypeSlidesIcon className={className} /> | ||
) : fileType === 'link' ? ( | ||
<FileTypeLinkIcon className={className} /> | ||
) : ( | ||
<FileTypeUnknownIcon className={className} /> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters