From 0bfcf77f381f1178753558df194a04bfb7e5699e Mon Sep 17 00:00:00 2001
From: mbaharip <62494292+mbahArip@users.noreply.github.com>
Date: Mon, 8 May 2023 11:31:47 +0700
Subject: [PATCH] Fix list view copy and download, and Make SWRLayout not
inside a card on file preview
---
src/components/File/List.tsx | 104 ++++++------------
.../FilePreview/AudioPreview/index.tsx | 1 +
.../FilePreview/CodePreview/index.tsx | 1 +
.../FilePreview/ImagePreview/index.tsx | 9 +-
.../FilePreview/MarkdownPreview/index.tsx | 1 +
.../FilePreview/PDFPreview/index.tsx | 1 +
.../FilePreview/TextPreview/index.tsx | 1 +
src/components/layout/SWRLayout/index.tsx | 13 ++-
src/pages/folder/[id].tsx | 2 +-
9 files changed, 57 insertions(+), 76 deletions(-)
diff --git a/src/components/File/List.tsx b/src/components/File/List.tsx
index 27ea95f..bf2100d 100644
--- a/src/components/File/List.tsx
+++ b/src/components/File/List.tsx
@@ -1,76 +1,24 @@
import { drive_v3 } from "googleapis";
import Link from "next/link";
import { formatBytes, formatDate } from "utils/formatHelper";
-import { toast } from "react-toastify";
import { MdContentCopy, MdDownload } from "react-icons/md";
import { getFileIcon } from "utils/mimeTypesHelper";
import { BsFolderFill } from "react-icons/bs";
import siteConfig from "config/site.config";
import { createFileId } from "utils/driveHelper";
+import useCopyText from "hooks/useCopyText";
type Props = {
data: drive_v3.Schema$File;
};
-function CopyButton({ url, isFolder }: { url: string; isFolder: boolean }) {
- return (
-
- );
-}
-function DownloadButton({
- fileId,
- fileName,
-}: {
- fileId: string;
- fileName: string;
-}) {
- return (
-
- );
-}
-
export default function ListFile({ data }: Props) {
const isFolder = data.mimeType === "application/vnd.google-apps.folder";
const Icon = isFolder
? BsFolderFill
: getFileIcon(data.fileExtension as string, data.mimeType as string);
+ const copyText = useCopyText();
+
if (!data) return null;
return (
@@ -122,19 +70,39 @@ export default function ListFile({ data }: Props) {
{isFolder ? "" : formatBytes(data.size as string)}
-
- {isFolder ? null : (
-
+
+ {!isFolder && (
+ {
+ e.stopPropagation();
+ }}
+ >
+
+
)}
diff --git a/src/components/FilePreview/AudioPreview/index.tsx b/src/components/FilePreview/AudioPreview/index.tsx
index 4bcd939..c8210bc 100644
--- a/src/components/FilePreview/AudioPreview/index.tsx
+++ b/src/components/FilePreview/AudioPreview/index.tsx
@@ -45,6 +45,7 @@ export default function AudioPreview({ data }: Props) {
data={data}
error={errorMessage}
isLoading={isLoading}
+ useCard={false}
>
diff --git a/src/components/FilePreview/ImagePreview/index.tsx b/src/components/FilePreview/ImagePreview/index.tsx
index 0c5e79d..2dc3fd4 100644
--- a/src/components/FilePreview/ImagePreview/index.tsx
+++ b/src/components/FilePreview/ImagePreview/index.tsx
@@ -1,12 +1,12 @@
-import { TFile } from "types/googleapis";
import { drive_v3 } from "googleapis";
import { useEffect, useState } from "react";
import config from "config/site.config";
import { reverseString } from "utils/hashHelper";
import SWRLayout from "components/layout/SWRLayout";
+import { createFileId } from "utils/driveHelper";
type Props = {
- data: TFile | drive_v3.Schema$File;
+ data: drive_v3.Schema$File;
hash?: string;
};
@@ -21,7 +21,7 @@ export default function ImagePreview({ data, hash }: Props) {
setIsLoading(false);
}, config.preview.timeout);
const image = new Image();
- image.src = `/media/${data.id}/${data.name}`;
+ image.src = `/api/files/${createFileId(data)}?download=1`;
image.onload = () => {
setImageSrc(image.src);
setIsLoading(false);
@@ -36,7 +36,7 @@ export default function ImagePreview({ data, hash }: Props) {
return () => {
clearTimeout(timeout);
};
- }, [data.id, data.name]);
+ }, [data]);
return (
@@ -44,6 +44,7 @@ export default function ImagePreview({ data, hash }: Props) {
data={data}
error={errorMessage}
isLoading={isLoading}
+ useCard={false}
>
diff --git a/src/components/FilePreview/PDFPreview/index.tsx b/src/components/FilePreview/PDFPreview/index.tsx
index fea6740..f1acf31 100644
--- a/src/components/FilePreview/PDFPreview/index.tsx
+++ b/src/components/FilePreview/PDFPreview/index.tsx
@@ -33,6 +33,7 @@ export default function PDFPreview({ data }: Props) {
data={data}
error={errorMessage}
isLoading={isLoading}
+ useCard={false}
>
<>>
diff --git a/src/components/FilePreview/TextPreview/index.tsx b/src/components/FilePreview/TextPreview/index.tsx
index 382074d..418e83f 100644
--- a/src/components/FilePreview/TextPreview/index.tsx
+++ b/src/components/FilePreview/TextPreview/index.tsx
@@ -22,6 +22,7 @@ export default function TextPreview({ data }: Props) {
data={swrData}
error={error}
isLoading={isLoading}
+ useCard={false}
>
diff --git a/src/components/layout/SWRLayout/index.tsx b/src/components/layout/SWRLayout/index.tsx
index d5a9497..e4ecf14 100644
--- a/src/components/layout/SWRLayout/index.tsx
+++ b/src/components/layout/SWRLayout/index.tsx
@@ -6,10 +6,17 @@ type Props = {
data: unknown;
error: unknown;
isLoading: boolean;
+ useCard?: boolean;
children: React.ReactNode;
};
-export default function SWRLayout({ data, error, isLoading, children }: Props) {
+export default function SWRLayout({
+ data,
+ error,
+ isLoading,
+ useCard = true,
+ children,
+}: Props) {
const [isMounted, setIsMounted] = useState
(false);
useEffect(() => {
@@ -21,12 +28,12 @@ export default function SWRLayout({ data, error, isLoading, children }: Props) {
return (
<>
{isLoading && (
-
+
)}
{!isLoading && error && (
-
+
)}
diff --git a/src/pages/folder/[id].tsx b/src/pages/folder/[id].tsx
index 6580007..9eaa9d3 100644
--- a/src/pages/folder/[id].tsx
+++ b/src/pages/folder/[id].tsx
@@ -110,7 +110,7 @@ export default function Home({ id, folderName, bannerFileId }: Props) {
openGraph={{
title: folderName,
url: `${process.env.NEXT_PUBLIC_DOMAIN}/folder/${id}`,
- description: `Exploring ${folderName}}`,
+ description: `Exploring ${folderName}`,
images: [
{
url: bannerFileId