Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: fallback to proper icon

Pranav Cea126abc711d
diff --git a/packages/nc-gui/components/cell/attachment/Card.vue b/packages/nc-gui/components/cell/attachment/Card.vue
index ef2dbdd032..eb63ceb4c4 100644
--- a/packages/nc-gui/components/cell/attachment/Card.vue
+++ b/packages/nc-gui/components/cell/attachment/Card.vue
@@ -125,8 +125,13 @@ const handleFileDeleteStart = () => {
:width="45"
/>
<component :is="FileIcon(attachment.icon)" v-else-if="attachment.icon" :height="45" :width="45" class="text-white" />
-
- <GeneralIcon v-else icon="ncFileTypeUnknown" :height="45" :width="45" class="text-white" />
+ <GeneralIcon
+ :icon ="getAttachmentIcon(attachment.title, attachment.mimetype)"
+ v-else
+ :height="45"
+ :width="45"
+ class="text-white"
+ />
</div>
<div class="relative px-1 pb-1 items-center flex" :title="attachment.title">
diff --git a/packages/nc-gui/composables/useAttachmentIcon.ts b/packages/nc-gui/composables/useAttachmentIcon.ts
index c67de2c1ee..2cb815b845 100644
--- a/packages/nc-gui/composables/useAttachmentIcon.ts
+++ b/packages/nc-gui/composables/useAttachmentIcon.ts
@@ -3,38 +3,6 @@ export const useAttachmentIcon = (
mimetype: MaybeRefOrGetter<string | undefined>,
) => {
return computed<keyof typeof iconMap>(() => {
- if (isImage(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypeImage'
- }
-
- if (isPdf(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypePdf'
- }
-
- if (isVideo(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypeVideo'
- }
-
- if (isAudio(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypeAudio'
- }
-
- if (isWord(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypeWord'
- }
-
- if (isExcel(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypeCsv'
- }
-
- if (isPresentation(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypePresentation'
- }
-
- if (isZip(toValue(title) || '', toValue(mimetype))) {
- return 'ncFileTypeZip'
- }
-
- return 'ncFileTypeUnknown'
+ return getAttachmentIcon(title, mimetype)
})
}
diff --git a/packages/nc-gui/utils/fileUtils.ts b/packages/nc-gui/utils/fileUtils.ts
index aceb97d571..5279ab439d 100644
--- a/packages/nc-gui/utils/fileUtils.ts
+++ b/packages/nc-gui/utils/fileUtils.ts
@@ -175,3 +175,40 @@ export const getReadableFileSize = (sizeInBytes: number) => {
const i = Math.min(Math.floor(Math.log(sizeInBytes) / Math.log(1024)), 4)
return `${(sizeInBytes / 1024 ** i).toFixed(2) * 1} ${['B', 'KB', 'MB', 'GB', 'TB'][i]}`
}
+
+export const getAttachmentIcon = ( title: MaybeRefOrGetter<string | undefined>,
+ mimetype: MaybeRefOrGetter<string | undefined>,) => {
+ if (isImage(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypeImage'
+ }
+
+ if (isPdf(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypePdf'
+ }
+
+ if (isVideo(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypeVideo'
+ }
+
+ if (isAudio(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypeAudio'
+ }
+
+ if (isWord(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypeWord'
+ }
+
+ if (isExcel(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypeCsv'
+ }
+
+ if (isPresentation(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypePresentation'
+ }
+
+ if (isZip(toValue(title) || '', toValue(mimetype))) {
+ return 'ncFileTypeZip'
+ }
+
+ return 'ncFileTypeUnknown'
+}