From a3644b50e57f1f177cb04ebd3e425cf3f0a4dd23 Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Sun, 29 Aug 2021 17:14:17 +0100 Subject: [PATCH] add action buttons to file listing, close #50 --- components/FileListing.tsx | 85 +++++++++++++++++++++++++++----------- pages/_app.tsx | 8 +++- 2 files changed, 67 insertions(+), 26 deletions(-) diff --git a/components/FileListing.tsx b/components/FileListing.tsx index e57eb45..d5f2d39 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -65,8 +65,8 @@ const FileListItem: FunctionComponent<{ const renderEmoji = emojiIcon && !emojiIcon.index return ( -
-
+
+
{/*
{c.file ? c.file.mimeType : 'folder'}
*/}
{renderEmoji ? ( @@ -79,7 +79,7 @@ const FileListItem: FunctionComponent<{ {renderEmoji ? c.name.replace(emojiIcon ? emojiIcon[0] : '', '').trim() : c.name}
-
+
{new Date(c.lastModifiedDateTime).toLocaleString('en-US', { year: 'numeric', month: '2-digit', @@ -89,7 +89,7 @@ const FileListItem: FunctionComponent<{ hour12: false, })}
-
+
{humanFileSize(c.size)}
@@ -164,10 +164,11 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = return (
-
-
Name
-
Last Modified
+
+
Name
+
Last Modified
Size
+
Actions
@@ -197,7 +198,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = return toolbars.concat([ { key: 'copy', - render: , + render: , onClick: i => { clipboard.copy(i.alt ? `${getBaseUrl()}/api?path=${path + '/' + i.alt}&raw=true` : '') toast.success('Copied image permanent link to clipboard.') @@ -209,20 +210,56 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = )} {children.map((c: any) => ( -
{ - e.preventDefault() +
+
{ + e.preventDefault() - if (!c.folder && fileIsImage(c.name)) { - setActiveImageIdx(imageIndexDict[c.id]) - setImageViewerVisibility(true) - } else { - router.push(`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`) - } - }} - > - + if (!c.folder && fileIsImage(c.name)) { + setActiveImageIdx(imageIndexDict[c.id]) + setImageViewerVisibility(true) + } else { + router.push(`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`) + } + }} + > + +
+ {c.folder ? ( +
+ { + clipboard.copy(`${getBaseUrl()}${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`) + toast.success('Copied folder permanent link to clipboard.') + }} + > + + +
+ ) : ( +
+ { + clipboard.copy(`${getBaseUrl()}/api?path=${path === '/' ? '' : path}/${c.name}&raw=true`) + toast.success('Copied permanent raw file link to clipboard.') + }} + > + + + + + +
+ )}
))} @@ -272,13 +309,13 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = return default: - return
{fileName}
+ return
{fileName}
} } return ( <> -
+
@@ -291,7 +328,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = } return ( -
+
) diff --git a/pages/_app.tsx b/pages/_app.tsx index dff5792..8d5f6e9 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -16,16 +16,18 @@ import { faFileAlt, faFile, faFolder, + faCopy, + faArrowAltCircleDown, } from '@fortawesome/free-regular-svg-icons' import { faPlus, faMinus, + faCopy as faCopySolid, faDownload, faMusic, faArrowLeft, faArrowRight, faFileDownload, - faCopy, faUndo, faBook, } from '@fortawesome/free-solid-svg-icons' @@ -53,11 +55,13 @@ library.add( faArrowRight, faFileDownload, faCopy, + faCopySolid, faPlus, faMinus, faDownload, faUndo, - faBook + faBook, + faArrowAltCircleDown ) function MyApp({ Component, pageProps }: AppProps) {