From 550377580bd171876f0c8e206a93d5af1155967d Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 25 Mar 2023 21:17:17 -0600 Subject: [PATCH] Displaying poster file in FileCard if the FileGroup has a poster file. --- app/src/components/Files.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/components/Files.js b/app/src/components/Files.js index 4e0cf8e0..2dfa04e0 100644 --- a/app/src/components/Files.js +++ b/app/src/components/Files.js @@ -41,7 +41,7 @@ import {FileBrowser} from "./FileBrowser"; import {refreshDirectoryFiles, refreshFiles} from "../api"; import {useSubscribeEventName} from "../Events"; import {FilePreviewContext} from "./FilePreview"; -import {TagsContext} from "../Tags"; +import {taggedImageLabel, TagsContext} from "../Tags"; export function FilesPage() { @@ -121,6 +121,18 @@ function ImageCard({file}) { } +function findPosterPath(files) { + if (_.isEmpty(files)) { + return; + } + for (let i = 0; i < files.length; i++) { + const file = files[i]; + if (file['mimetype'] && file['mimetype'].startsWith('image/')) { + return file['path']; + } + } +} + function FileCard({file}) { const {s} = useContext(ThemeContext); @@ -138,7 +150,7 @@ function FileCard({file}) { return ; } - const {data} = file; + const {data, tags} = file; let author; if (data) { author = data['author']; @@ -147,11 +159,17 @@ function FileCard({file}) { const color = mimetypeColor(file.mimetype); const size = file.size !== null && file.size !== undefined ? humanFileSize(file.size) : null; + const posterFile = findPosterPath(file['files']); + let poster = ; + let imageLabel = !_.isEmpty(tags) ? taggedImageLabel : null; + if (posterFile) { + const posterUrl = `/media/${encodeURIComponent(posterFile)}`; + poster = ; + } + return - - - + {poster}