From c3f60b1e643ff2e9ccf8f483a971b1970cf7d786 Mon Sep 17 00:00:00 2001 From: enes Date: Tue, 6 Aug 2024 13:29:43 +0200 Subject: [PATCH] feat: extension icon label util component --- src/components/DisplaySigit/index.tsx | 41 +++++-------- src/components/getExtensionIconLabel.tsx | 76 ++++++++++++++++++++++++ src/pages/home/index.tsx | 2 - 3 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 src/components/getExtensionIconLabel.tsx diff --git a/src/components/DisplaySigit/index.tsx b/src/components/DisplaySigit/index.tsx index 2b49f2f..99637ad 100644 --- a/src/components/DisplaySigit/index.tsx +++ b/src/components/DisplaySigit/index.tsx @@ -13,7 +13,7 @@ import { faCalendar, faCopy, faEye, - faFilePdf + faFile } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { UserAvatar } from '../UserAvatar' @@ -21,6 +21,7 @@ import { UserAvatarGroup } from '../UserAvatarGroup' import styles from './style.module.scss' import { TooltipChild } from '../TooltipChild' +import { getExtensionIconLabel } from '../getExtensionIconLabel' type SigitProps = { meta: Meta @@ -28,30 +29,14 @@ type SigitProps = { setProfiles: Dispatch> } -// function -// const ExtensionIconMapper = new Map([ -// [ -// 'pdf', -// <> -// PDF -// -// ], -// [ -// 'csv', -// <> -// CSV -// -// ] -// ]) - export const DisplaySigit = ({ meta, profiles, setProfiles }: SigitProps) => { const { title, createdAt, submittedBy, signers, - signedStatus - // fileExtensions + signedStatus, + fileExtensions } = useSigitMeta(meta) useEffect(() => { @@ -164,13 +149,17 @@ export const DisplaySigit = ({ meta, profiles, setProfiles }: SigitProps) => { {signedStatus} - - {/* {fileExtensions.map(ext => - - return - )} */} - {'PDF'} - + {fileExtensions.length > 0 ? ( + + {fileExtensions.length > 1 ? ( + <> + Multiple File Types + + ) : ( + getExtensionIconLabel(fileExtensions[0]) + )} + + ) : null}
diff --git a/src/components/getExtensionIconLabel.tsx b/src/components/getExtensionIconLabel.tsx new file mode 100644 index 0000000..d745814 --- /dev/null +++ b/src/components/getExtensionIconLabel.tsx @@ -0,0 +1,76 @@ +import { + faFilePdf, + faFileExcel, + faFileWord, + faFilePowerpoint, + faFileZipper, + faFileCsv, + faFileLines, + faFileImage, + faFile, + IconDefinition +} from '@fortawesome/free-solid-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' + +export const getExtensionIconLabel = (extension: string) => { + let icon: IconDefinition + switch (extension.toLowerCase()) { + case 'pdf': + icon = faFilePdf + break + case 'json': + icon = faFilePdf + break + + case 'xslx': + case 'xsl': + icon = faFileExcel + break + + case 'doc': + case 'docx': + icon = faFileWord + break + + case 'ppt': + case 'pptx': + icon = faFilePowerpoint + break + + case 'zip': + case '7z': + case 'rar': + case 'tar': + case 'gz': + icon = faFileZipper + break + + case 'csv': + icon = faFileCsv + break + + case 'txt': + icon = faFileLines + break + + case 'png': + case 'jpg': + case 'jpeg': + case 'gif': + case 'svg': + case 'bmp': + case 'ico': + icon = faFileImage + break + + default: + icon = faFile + return + } + + return ( + <> + {extension.toUpperCase()} + + ) +} diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 07304b6..e765110 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -103,8 +103,6 @@ export const HomePage = () => { const [isFilterVisible, setIsFilterVisible] = useState(true) const [sort, setSort] = useState('asc') - console.log(filter, sort) - return (