From 2b8d1a957bf487648228375b3f86c029bc9f70d8 Mon Sep 17 00:00:00 2001 From: Mohammed JBILOU <95973236+Molaryy@users.noreply.github.com> Date: Wed, 6 Sep 2023 22:46:17 +0200 Subject: [PATCH] feat: added reviewed icons --- src/components/cards/FileCard.tsx | 186 +++++++++++++++---------- src/components/folder/UploadFolder.tsx | 2 +- 2 files changed, 116 insertions(+), 72 deletions(-) diff --git a/src/components/cards/FileCard.tsx b/src/components/cards/FileCard.tsx index c7f0fd89..2b56c8e7 100644 --- a/src/components/cards/FileCard.tsx +++ b/src/components/cards/FileCard.tsx @@ -1,87 +1,131 @@ -import { Box, HStack, Text, useBreakpointValue, useDisclosure, useColorModeValue } from '@chakra-ui/react'; -import { useState } from 'react'; -import { BsFileEarmarkFill } from 'react-icons/bs'; - -import { IPCFile } from 'types/types'; - +import {Box, HStack, Text, useBreakpointValue, useColorModeValue, useDisclosure} from '@chakra-ui/react'; +import {useState} from 'react'; +import {BsFileEarmarkFill} from 'react-icons/bs'; +import { + BiLogoCPlusPlus, + BiLogoCss3, + BiLogoFlutter, + BiLogoGoLang, + BiLogoHtml5, + BiLogoJavascript, + BiLogoPython, + BiLogoReact, + BiLogoTypescript, + BiText +} from "react-icons/bi"; +import {VscTerminalBash} from "react-icons/vsc"; +import {FaRust} from "react-icons/fa"; +import {IPCFile} from 'types/types'; +import {DiHaskell} from "react-icons/di"; +import {SiYaml} from "react-icons/si"; import useToggle from 'hooks/useToggle'; -import { useDriveContext } from 'contexts/drive'; -import { useUserContext } from 'contexts/user'; +import {useDriveContext} from 'contexts/drive'; +import {useUserContext} from 'contexts/user'; import formatDate from 'utils/formatDate'; import formatFileSize from 'utils/formatFileSize'; -import { FileOptionsDrawer, FileOptionsPopover } from 'components/dashboardPage/FileOptions'; +import {FileOptionsDrawer, FileOptionsPopover} from 'components/dashboardPage/FileOptions'; -import { textColorMode } from 'config/colorMode'; +import {textColorMode} from 'config/colorMode'; import Card from './Card'; -const FileCard = ({ file }: { file: IPCFile }): JSX.Element => { - const { files } = useDriveContext(); - const { - user: { - fullContact: { - contact: { username }, - }, - }, - } = useUserContext(); +const fileTypePreview = (fileName: string) => { + const fileIcons: { [key: string]: React.ReactElement } = { + '.py': , + '.ts': , + '.js': , + '.cpp': , + '.hpp': , + '.css': , + '.html': , + '.tsx': , + '.jsx': , + '.go': , + '.dart': , + '.txt': , + '.sh': , + '.rs': , + '.hs': , + '.lhs': , + '.yml': + }; + + const fileExtension: string = fileName.slice(fileName.lastIndexOf('.') + 1); + + if (fileIcons[`.${fileExtension}`]) { + return fileIcons[`.${fileExtension}`]; + } + return ; +}; + +const FileCard = ({file}: { file: IPCFile }): JSX.Element => { + const {files} = useDriveContext(); + const { + user: { + fullContact: { + contact: {username}, + }, + }, + } = useUserContext(); - const { isOpen: isOpenFile, onOpen: onOpenFile, onClose: onCloseFile } = useDisclosure(); - const { toggle: popoverOpeningToggleFile, toggleHandler: popoverOpeningHandlerFile } = useToggle(); + const {isOpen: isOpenFile, onOpen: onOpenFile, onClose: onCloseFile} = useDisclosure(); + const {toggle: popoverOpeningToggleFile, toggleHandler: popoverOpeningHandlerFile} = useToggle(); - const [clickPosition, setClickPosition] = useState({ x: 0, y: 0 }); + const [clickPosition, setClickPosition] = useState({x: 0, y: 0}); - const isDrawer = useBreakpointValue({ base: true, sm: false }) || false; - const textColor = useColorModeValue(textColorMode.light, textColorMode.dark); - return ( - <> - { - e.preventDefault(); - if (!isDrawer) { - setClickPosition({ x: e.clientX, y: e.clientY }); - popoverOpeningHandlerFile(); - } else onOpenFile(); - }} - > - - - - - {file.name} - - - - - by{' '} - - {username} - - - {formatDate(file.createdAt)} - {formatFileSize(file.size)} - - - - - {isDrawer ? ( - - ) : ( - - )} - - - ); + const isDrawer = useBreakpointValue({base: true, sm: false}) || false; + const textColor = useColorModeValue(textColorMode.light, textColorMode.dark); + const icon = fileTypePreview(file.name); + return ( + <> + { + e.preventDefault(); + if (!isDrawer) { + setClickPosition({x: e.clientX, y: e.clientY}); + popoverOpeningHandlerFile(); + } else onOpenFile(); + }} + > + + + {icon} + + {file.name} + + + + + by{' '} + + {username} + + + {formatDate(file.createdAt)} + {formatFileSize(file.size)} + + + + + {isDrawer ? ( + + ) : ( + + )} + + + ); }; export default FileCard; diff --git a/src/components/folder/UploadFolder.tsx b/src/components/folder/UploadFolder.tsx index a9f867ef..fb5fbf78 100644 --- a/src/components/folder/UploadFolder.tsx +++ b/src/components/folder/UploadFolder.tsx @@ -93,7 +93,7 @@ const UploadFolder = (): JSX.Element => { const filesContent: ArrayBuffer[] = []; const getAllFiles = async (fileInfo: FileInfo[], filesEvent: FileList) => { - + // eslint-disable-next-line no-await-in-loop, no-restricted-syntax for (const e of filesEvent) { // eslint-disable-next-line no-await-in-loop