From b26b12c7b262f20fed60a92d5c5f67dd11e7ff73 Mon Sep 17 00:00:00 2001 From: mbaharip <62494292+mbahArip@users.noreply.github.com> Date: Thu, 25 May 2023 20:29:39 +0700 Subject: [PATCH] Move file type into Enums, Change download URL. --- .../{ => (__components)}/compListLayout.tsx | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) rename src/app/{ => (__components)}/compListLayout.tsx (89%) diff --git a/src/app/compListLayout.tsx b/src/app/(__components)/compListLayout.tsx similarity index 89% rename from src/app/compListLayout.tsx rename to src/app/(__components)/compListLayout.tsx index 2e472f5..a9bff43 100644 --- a/src/app/compListLayout.tsx +++ b/src/app/(__components)/compListLayout.tsx @@ -1,21 +1,25 @@ "use client"; -import { FilesResponse } from "types/api/files"; import { drive_v3 } from "googleapis"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; import { MdContentCopy, MdDownload, MdFolder, MdPlayCircle, } from "react-icons/md"; -import getFileGroup from "utils/fileHelper/typeMap"; -import siteConfig from "config/site.config"; -import Link from "next/link"; -import { usePathname } from "next/navigation"; + +import useCopyText from "hooks/useCopyText"; import formatDate from "utils/fileHelper/formatDate"; import formatSize from "utils/fileHelper/formatSize"; -import useCopyText from "hooks/useCopyText"; +import getFileGroup from "utils/fileHelper/typeMap"; + +import { FilesResponse } from "types/api/files"; +import { Constant } from "types/general/constant"; + import apiConfig from "config/api.config"; +import siteConfig from "config/site.config"; type Props = { data: FilesResponse; @@ -77,7 +81,7 @@ function ListLayout({ data }: Props) { {data.folders.map((folder) => ( (
@@ -154,7 +158,7 @@ function ListFolder({ "hidden text-center tablet:col-span-1 tablet:block" } > - Folder + {Constant.type_folder} 2 - ? "capitalize" - : "uppercase" - }`} + className={`hidden text-center capitalize tablet:col-span-1 tablet:block`} > - {fileGroup === "default" ? "Unknown" : fileGroup} + {Constant[`type_${fileGroup}`] ?? + Constant.type_default} @@ -284,13 +286,22 @@ function ListFile({ } function Action({ - path, + path = "", + encryptedId = "", isDownloadable = false, }: { - path: string; + path?: string; + encryptedId?: string; isDownloadable?: boolean; }) { const copyLink = useCopyText(); + let url: string = ""; + if (path) { + url = `${apiConfig.basePath}${path}`; + } + if (path && isDownloadable) { + url = `${apiConfig.basePath}/download${path}`; + } return (
{ e.preventDefault(); e.stopPropagation(); - copyLink(`${apiConfig.basePath}${path}/download`); + copyLink(url); }} > { e.stopPropagation(); }} + className={ + "global-duration grid aspect-square h-8 w-8 cursor-pointer place-items-center rounded-full p-1 transition-colors hover:bg-zinc-300 active:bg-zinc-400 dark:hover:bg-zinc-700 dark:active:bg-zinc-600" + } >