From a2a265af027cfdb1e5a884e9bbc5ad6d30671690 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Thu, 10 Nov 2022 01:05:27 +0100 Subject: [PATCH] Dashboard: Single file mode (#4188) * progress pause/resume should be white * add uppy-c-btn to remaining buttons * Single file mode: large preview thumbnail for single file * tweak icon and FileItem sizes * check for single file mode when files are added or removed * Don't shorted file names in single file mode * Refactor a bit * remove events on uninstall --- packages/@uppy/dashboard/src/Dashboard.jsx | 24 ++++++++++++++ .../dashboard/src/components/Dashboard.jsx | 4 +++ .../src/components/FileItem/Buttons/index.jsx | 2 +- .../components/FileItem/Buttons/index.scss | 31 ++++++++++--------- .../components/FileItem/FileInfo/index.jsx | 5 ++- .../components/FileItem/FileInfo/index.scss | 13 ++++++++ .../FileItem/FileProgress/index.jsx | 2 +- .../FileItem/FileProgress/index.scss | 1 + .../src/components/FileItem/index.jsx | 1 + .../src/components/FileItem/index.scss | 29 +++++++++++++++-- .../dashboard/src/components/FileList.jsx | 20 ++++++------ packages/@uppy/dashboard/src/style.scss | 16 ++++++++++ 12 files changed, 118 insertions(+), 30 deletions(-) diff --git a/packages/@uppy/dashboard/src/Dashboard.jsx b/packages/@uppy/dashboard/src/Dashboard.jsx index bbb5897b5f..fca44f4fe0 100644 --- a/packages/@uppy/dashboard/src/Dashboard.jsx +++ b/packages/@uppy/dashboard/src/Dashboard.jsx @@ -705,6 +705,24 @@ export default class Dashboard extends UIPlugin { this.uppy.emit('restore-canceled') } + #generateLargeThumbnailIfSingleFile = () => { + if (this.opts.disableThumbnailGenerator) { + return + } + + const LARGE_THUMBNAIL = 600 + const files = this.uppy.getFiles() + + if (files.length === 1) { + const thumbnailGenerator = this.uppy.getPlugin(`${this.id}:ThumbnailGenerator`) + thumbnailGenerator?.setOptions({ thumbnailWidth: LARGE_THUMBNAIL }) + const fileForThumbnail = { ...files[0], preview: undefined } + thumbnailGenerator.requestThumbnail(fileForThumbnail).then(() => { + thumbnailGenerator?.setOptions({ thumbnailWidth: this.opts.thumbnailWidth }) + }) + } + } + #openFileEditorWhenFilesAdded = (files) => { const firstFile = files[0] if (this.canEditFile(firstFile)) { @@ -732,6 +750,9 @@ export default class Dashboard extends UIPlugin { this.uppy.on('file-editor:complete', this.hideAllPanels) this.uppy.on('complete', this.handleComplete) + this.uppy.on('files-added', this.#generateLargeThumbnailIfSingleFile) + this.uppy.on('file-removed', this.#generateLargeThumbnailIfSingleFile) + // ___Why fire on capture? // Because this.ifFocusedOnUppyRecently needs to change before onUpdate() fires. document.addEventListener('focus', this.recordIfFocusedOnUppyRecently, true) @@ -762,6 +783,9 @@ export default class Dashboard extends UIPlugin { this.uppy.off('file-editor:complete', this.hideAllPanels) this.uppy.off('complete', this.handleComplete) + this.uppy.off('files-added', this.#generateLargeThumbnailIfSingleFile) + this.uppy.off('file-removed', this.#generateLargeThumbnailIfSingleFile) + document.removeEventListener('focus', this.recordIfFocusedOnUppyRecently) document.removeEventListener('click', this.recordIfFocusedOnUppyRecently) diff --git a/packages/@uppy/dashboard/src/components/Dashboard.jsx b/packages/@uppy/dashboard/src/components/Dashboard.jsx index 7a3a1420a5..afdb0e42f0 100644 --- a/packages/@uppy/dashboard/src/components/Dashboard.jsx +++ b/packages/@uppy/dashboard/src/components/Dashboard.jsx @@ -20,6 +20,8 @@ const HEIGHT_MD = 400 export default function Dashboard (props) { const noFiles = props.totalFileCount === 0 + const singleFile = props.totalFileCount === 1 + const isSizeMD = props.containerWidth > WIDTH_MD const dashboardClassName = classNames({ @@ -35,6 +37,7 @@ export default function Dashboard (props) { 'uppy-size--height-md': props.containerHeight > HEIGHT_MD, 'uppy-Dashboard--isAddFilesPanelVisible': props.showAddFilesPanel, 'uppy-Dashboard--isInnerWrapVisible': props.areInsidesReadyToBeVisible, + 'uppy-Dashboard--singleFile': singleFile, }) // Important: keep these in sync with the percent width values in `src/components/FileItem/index.scss`. @@ -135,6 +138,7 @@ export default function Dashboard (props) { ) : ( diff --git a/packages/@uppy/dashboard/src/components/FileItem/Buttons/index.jsx b/packages/@uppy/dashboard/src/components/FileItem/Buttons/index.jsx index a609e50193..0f23814d8e 100644 --- a/packages/@uppy/dashboard/src/components/FileItem/Buttons/index.jsx +++ b/packages/@uppy/dashboard/src/components/FileItem/Buttons/index.jsx @@ -15,7 +15,7 @@ function EditButton ({ ) { return (