From d0d315cd671d7d229fa1cb1abe6bd07b573ca514 Mon Sep 17 00:00:00 2001 From: Roland Date: Fri, 4 Aug 2023 11:32:47 -0600 Subject: [PATCH] Always previewing file that can be downloaded. --- app/src/components/Common.js | 87 +++++++++++++++---------------- app/src/components/FilePreview.js | 3 +- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 5355b2d9..5d738eb3 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -550,55 +550,52 @@ export function CardPoster({to, file}) { let posterPath = findPosterPath(file); - if (!posterPath && to && (to.startsWith('/download/') || to.startsWith('/media/'))) { - // No poster, link is to download a file directly. - return - { - window.location.href = to; - return null - }}> - {imageLabel} - - - - } else if (!posterPath && to) { - // No poster, link to the full page. - return - navigate(to)}> - {imageLabel} - - - - } else if (!posterPath) { - // No poster, no to, use a Preview. - return - - {imageLabel} - - - - } + if (posterPath) { + // FileGroup has a poster (screenshot/thumbnail) file. + posterPath = `/media/${encodeMediaPath(posterPath)}`; - posterPath = `/media/${encodeMediaPath(posterPath)}`; + const image = <> + {/* Replicate but with maxHeight applied to image */} + {imageLabel} + poster + ; - const image = <> - {/* Replicate but with maxHeight applied to image */} - {imageLabel} - poster - ; - - if (to) { - // Link using React Router. - return - {image} - - } else { - // Preview the file. - return
- + if (to) { + // Link within this App. + console.debug(`${file['primary_path']} link with poster`); + return {image} + + } else { + // Preview the file. + console.debug(`${file['primary_path']} preview with poster`); + return
+ + {image} + +
+ } + } else { + // FileGroup has no poster. + if (!to || (to.startsWith('/media/') || to.startsWith('/download/'))) { + // "to" is a downloadable file outside the app, preview the file. + console.debug(`${file['primary_path']} preview no poster`); + return + + {imageLabel} + + -
+ } else if (!posterPath && to) { + // Link to the full page in this App. + console.debug(`${file['primary_path']} link no poster`); + return + navigate(to)}> + {imageLabel} + + + + } } } diff --git a/app/src/components/FilePreview.js b/app/src/components/FilePreview.js index 6fed88a4..25c0dc8c 100644 --- a/app/src/components/FilePreview.js +++ b/app/src/components/FilePreview.js @@ -140,6 +140,7 @@ function getSTLModal(previewFile) { } function getGenericModal(previewFile) { + // No special handler for this file type, just open it. const path = previewFile.primary_path ?? previewFile.path; const name = path.replace(/^.*[\\\/]/, ''); @@ -214,7 +215,7 @@ export function FilePreviewProvider({children}) {
{path}
: null; - console.log('path', path); + console.log('Previewing', path); setPreviewModal(