From de792ca342dece618d921c4eeefa2fa5f47c6177 Mon Sep 17 00:00:00 2001 From: Oksana Stepanenko Date: Mon, 12 Dec 2022 12:07:11 +0200 Subject: [PATCH] CHANGE | Show file icon by file type --- .../app/src/main/assets/fonts/fontello.ttf | Bin 26740 -> 43588 bytes src/assets/fonts/fontello.ttf | Bin 26740 -> 43588 bytes src/config/fontello.json | 182 ++++++++++++++++++ .../tasks/atoms/document-preview.atom.tsx | 7 +- .../plugins/chat/chat-item-file.component.tsx | 12 +- .../chat/message-media-preview.component.tsx | 6 +- src/shared/enums/file-type.enum.ts | 14 ++ src/shared/enums/index.ts | 3 +- src/shared/helpers/fs.helpers.ts | 36 ++++ 9 files changed, 252 insertions(+), 8 deletions(-) create mode 100644 src/shared/enums/file-type.enum.ts diff --git a/android/app/src/main/assets/fonts/fontello.ttf b/android/app/src/main/assets/fonts/fontello.ttf index e3fb9417c8e25bb105598a16ecd139410f5bd15b..a5d89c11681a769ccb40ddc1ca60aaa8ea09e2aa 100644 GIT binary patch delta 17355 zcmc&+d2kfhnSZalr@QCsWA1x2BWn}{5oRQfVvHpjh=~mqNSxScv&ImPLBt?g$QW?Y z69x=6U~@S(F#%)Z#7BH&A<1qkS?_MV+1!=d+D&;~N$sX8<&doZNNwU>XUmZNy`D?Q z%;-Sz3R*LLz4!I&?%(%)zwh_-ho92d|3x^~$et&Jt|El2UB7kRz=HXIcnRyT5@Or7 ze#cM)w&UliBlx9l8pv<`bn72?WBm+PUHNs}2e941`hI+>`FnP4TD!XIC?QG%A%}mm zdE>eb*Zt=HHbPGP4*PSPvBCa~?L9(HegNy&ZQeSx^8;VJ<4;$xVFfy!cTfNNbqC*h z$xX2o^89nh-~AMQ=j117H@)@bDLQ}7TZG~mLjHq@*0*{1bfD9>h(s=7yM%u@ z;_|I0-=>G-U8I}zkekV3vV<%pA11euW#l8|R&pE8kWcOv-aC0rP;?h>P&~wcE-vVdTrMu?mRv3_Fo0YxE--~$E-o;N zTrMs!k6gBv1Umi*R*D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3A`Vqbh<40{SwdyD^jKffHQ^ZKy2K6pbDzJ<~FQZKPLcbrfc-d>ymrU z97`#(q|0VkAV0H7ZZ#g~tSc05rqtE#3IfBb2DA^7Q{TK-*M z#ZsGxQDX>4kdR|O5`yDWI9n?t&sRG2dvsCrsXnbxC8^GT6}z(_%o34LqdyKU)vvYM zr83;6+EZ|*cdb1`{CykJpSm> zLkD)=Kd^1hU4?lzwWisyGA%wk^9jqbR&~&@D(9n7gK^mCECgnSiG^`KpAh2Ra;yd= zZb|8D1!|o1n?BG~#hEMbGMhRYN;0S%+wnq|u>>I&utb!Pnwb8_i!X7vc@}eS_+*)^ zHDzWc2c;|~?@R@5CZG)~%|3M5+$}BE^qwVMvIx!r=nsjGJIs=KscQuR9fSxcHP415ptsh=e={ ziip?LOs_T)M3QW3bwoGeO6`HaT`WR9B;fZ1`l8ei$)z7yq7&1ro0DP6c4V}QhZ``> zuFI&xyJpkwo8!yu4FSU#%wPz5Se2XL8J_M?5GNxFzYWtj!OHUX?;9FSryf7`*rNvz z?0aPYBW%y^U4st}Jvgu}zwy&+>jXCC34UzWW-^zN$3hNFOzy74HNgPl6AmjA6sxQv zEGpJ+XANAgE;QWtDY`7K?&hy8zM}qm=VFKcdbz0Z!8Eg~3al{GZ$=1G0uaM(sJbCP z1dLMo6v2m$?^u-sUP>r(bIZ!}`rv*bxWp1Cn@;rZxLaTJ4$;NS*hK#QTc^KU{QRer zzxr4wU4An5@pn%y`gr?E-|fTg%|B>a+5|VQh3*Ls#QUdZfFfg#}NG>Z;0Ez=aRu = ({ url, allowDelete, onDelete }) => { const prepareFileName = () => { const splitUrlArr = url.split('/') - return splitUrlArr[splitUrlArr.length - 1] } + const iconName = getIconNameByExtension(url) + const renderPreview = () => { if (isImage(url)) return ( @@ -71,7 +72,7 @@ export const DocumentPreview: FC = ({ url, allowDelete, onDelete }) => { return ( = props => { fsService.shareFile(content?.fileUrl, content?.name) }, [props.content]) + const iconName = getIconNameByExtension(props?.content?.fileUrl) + return ( = props => { diff --git a/src/shared/components/plugins/chat/message-media-preview.component.tsx b/src/shared/components/plugins/chat/message-media-preview.component.tsx index 86ce723c..4534ee69 100644 --- a/src/shared/components/plugins/chat/message-media-preview.component.tsx +++ b/src/shared/components/plugins/chat/message-media-preview.component.tsx @@ -1,4 +1,5 @@ import { $size, IconComponent, MessageType, useTheme } from '@/shared' +import { getIconNameByExtension } from '@/shared/helpers' import React, { useMemo, useState } from 'react' import { StyleSheet, Image, View, StyleProp, ViewStyle } from 'react-native' import Video from 'react-native-video' @@ -20,13 +21,14 @@ export const MessageMediaPreview = ({ const [paused, setPaused] = useState(false) + const iconName = getIconNameByExtension(uri) const getContent = () => { if (type === MessageType.File) return ( ) diff --git a/src/shared/enums/file-type.enum.ts b/src/shared/enums/file-type.enum.ts new file mode 100644 index 00000000..6179c756 --- /dev/null +++ b/src/shared/enums/file-type.enum.ts @@ -0,0 +1,14 @@ +export enum FileType { + DOC = "doc", + GIF = "gif", + JPEG = "jpeg", + JPG = "jpg", + MP3 = "mp3", + MP4 = "mp4", + PDF = "pdf", + PNG = "png", + SVG = "svg", + TXT = "txt", + XLS = "xls", + ZIP = "zip" +} \ No newline at end of file diff --git a/src/shared/enums/index.ts b/src/shared/enums/index.ts index 98c201d9..420feb75 100644 --- a/src/shared/enums/index.ts +++ b/src/shared/enums/index.ts @@ -14,4 +14,5 @@ export * from './btns-type.enum' export * from './actions-queue-type.enum' export * from './entity-type.enum' export * from './permissions.enum' -export * from './error-message.enum' \ No newline at end of file +export * from './error-message.enum' +export * from './file-type.enum' \ No newline at end of file diff --git a/src/shared/helpers/fs.helpers.ts b/src/shared/helpers/fs.helpers.ts index dea54b40..1001cbb0 100644 --- a/src/shared/helpers/fs.helpers.ts +++ b/src/shared/helpers/fs.helpers.ts @@ -1,4 +1,6 @@ +import _ from 'lodash' import { Alert, Platform } from 'react-native' +import { FileType } from '../enums' import { IFile } from '../interfaces' export const MAX_FILE_SIZE = 50000000 @@ -8,6 +10,21 @@ const DIGITS_REG_EXP = /\d+/ const M4A_EXT = 'm4a' const MOV_EXT = 'mov' +const iconByFileType = { + [FileType.DOC]: 'doc', + [FileType.JPG]: 'jpg', + [FileType.GIF]: 'gif', + [FileType.JPEG]: 'jpeg', + [FileType.MP3]: 'mp3', + [FileType.MP4]: 'mp4', + [FileType.PDF]: 'pdf', + [FileType.PNG]: 'png', + [FileType.SVG]: 'svg', + [FileType.TXT]: 'txt', + [FileType.XLS]: 'xls', + [FileType.ZIP]: 'zip' +}; + export const getFileName = (file: any) => { // Alert.alert('FILe', JSON.stringify(file)) try { @@ -146,3 +163,22 @@ export const getNameFromFileUrl = (url: string) => { return dirtyName; }; + +export const getFileType = (name: string) => { + if (!name) return null; + + const extension = getFileExtension(name); + if (_.isEmpty(extension)) return null; + + if (Object.values(FileType).includes(extension.toLowerCase() as FileType)) + return extension.toLowerCase() as FileType; + + return null; +}; + +export const getIconNameByExtension = (name: string) => { + const fileType = getFileType(name); + const iconByType = iconByFileType[fileType]; + if (iconByType) return iconByType; + return 'others'; +};