From c69d1f6702b8b943028176f62ddb202385479ef3 Mon Sep 17 00:00:00 2001 From: puri-ph4tt Date: Tue, 28 Nov 2023 16:47:38 +0700 Subject: [PATCH] fix: file-icon --- Services/client/src/components/FileIcon.vue | 30 +++++++------- Services/client/src/stores/file-info-data.ts | 43 ++++++++------------ 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/Services/client/src/components/FileIcon.vue b/Services/client/src/components/FileIcon.vue index 4ed9f4c..0de7cd0 100644 --- a/Services/client/src/components/FileIcon.vue +++ b/Services/client/src/components/FileIcon.vue @@ -6,26 +6,24 @@ const { mimeFileMapping } = useFileInfoStore() defineProps<{ fileMimeType: string | undefined; size: string }>() function getIcon(mimeType: string) { - if (mimeFileMapping.hasOwnProperty(mimeType)) { - return mimeFileMapping[mimeType].icon - } else { - return 'mdi-file-question-outline' - } + return mimeType && mimeFileMapping.hasOwnProperty(mimeType) + ? mimeFileMapping[mimeType].icon + : 'mdi-file-question-outline' } function getColor(mimeType: string) { - if (mimeFileMapping.hasOwnProperty(mimeType)) { - return mimeFileMapping[mimeType].color - } else { - return 'blue-11' - } + return mimeType && mimeFileMapping.hasOwnProperty(mimeType) + ? mimeFileMapping[mimeType].color + : 'blue-11' } -function getSize(s: string) { - if (s === 'preview') { - return '6em' +function getIconSize(s: string) { + type SizeMapping = { + [key: string]: string } - if (s === 'list') { - return '2em' + const sizeMapping: SizeMapping = { + preview: '6em', + list: '2em', } + return sizeMapping[s] } @@ -33,6 +31,6 @@ function getSize(s: string) { diff --git a/Services/client/src/stores/file-info-data.ts b/Services/client/src/stores/file-info-data.ts index 16d5bce..fa1d1a6 100644 --- a/Services/client/src/stores/file-info-data.ts +++ b/Services/client/src/stores/file-info-data.ts @@ -127,43 +127,34 @@ export const useFileInfoStore = defineStore('info', () => { } function getType(mimeType: any): string { - if (mimeType === undefined) { - return 'unknow type' - } else { - if (mimeFileMapping.hasOwnProperty(mimeType)) { - return mimeFileMapping[mimeType].type - } else { - return 'unknow type' - } - } + return mimeType && mimeFileMapping.hasOwnProperty(mimeType) + ? mimeFileMapping[mimeType].type + : 'unknown type' } function getFormatDate(dateTime: any): string { if (dateTime === undefined) { - return 'unknow date' - } else { - const date = new Date(dateTime) - const result = date.toLocaleDateString('th-TH', { - year: 'numeric', - month: 'long', - day: 'numeric', - }) - return result + return 'unknown date' } + const date = new Date(dateTime) + return date.toLocaleDateString('th-TH', { + year: 'numeric', + month: 'long', + day: 'numeric', + }) } function getSize(size: any): string { if (size === undefined) { return 'unknow size' - } else { - const units = ['B', 'KB', 'MB', 'GB', 'TB'] - let i = 0 - while (size >= 1024 && i < units.length - 1) { - size /= 1024 - i++ - } - return size.toFixed(2) + ' ' + units[i] } + const units = ['B', 'KB', 'MB', 'GB', 'TB'] + let i = 0 + while (size >= 1024 && i < units.length - 1) { + size /= 1024 + i++ + } + return size.toFixed(2) + ' ' + units[i] } async function getFileInfo(data: EhrFile) {