Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

cap 2

Manav Rathi72aab3f53c6f
diff --git a/web/packages/gallery/components/FileInfo.tsx b/web/packages/gallery/components/FileInfo.tsx
index 40d8d3e44d..4d90134a35 100644
--- a/web/packages/gallery/components/FileInfo.tsx
+++ b/web/packages/gallery/components/FileInfo.tsx
@@ -35,6 +35,7 @@ import {
import { formattedByteSize } from "@/gallery/utils/units";
import { type EnteFile } from "@/media/file";
import {
+ fileCaption,
fileCreationPhotoDate,
fileLocation,
filePublicMagicMetadata,
@@ -536,7 +537,7 @@ const Caption: React.FC<CaptionProps> = ({
}) => {
const [isSaving, setIsSaving] = useState(false);
- const caption = file.pubMagicMetadata?.data.caption ?? "";
+ const caption = fileCaption(file) ?? "";
const formik = useFormik<{ caption: string }>({
initialValues: { caption },
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 590af3e324..3cfb0679b8 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -26,6 +26,7 @@ import {
type FileInfoProps,
} from "@/gallery/components/FileInfo";
import type { Collection } from "@/media/collection";
+import { fileCaption } from "@/media/file-metadata";
import { FileType } from "@/media/file-type";
import type { EnteFile } from "@/media/file.js";
import { isHEICExtension, needsJPEGConversion } from "@/media/formats";
@@ -292,7 +293,15 @@ const FileViewer: React.FC<FileViewerProps> = ({
handleEditImage && canModify
? fileIsEditableImage(file)
: undefined;
- return { fileID, isOwnFile, showFavorite, isEditableImage };
+ const caption = fileCaption(file);
+
+ return {
+ fileID,
+ isOwnFile,
+ showFavorite,
+ isEditableImage,
+ caption,
+ };
},
[user, isInTrashSection, isInHiddenSection, handleEditImage],
);
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 0332a97b47..c13570ba49 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -58,6 +58,10 @@ export interface FileViewerFileAnnotation {
* and the edit action should therefore be shown for this file.
*/
isEditableImage: boolean;
+ /**
+ * The caption ("description") of the file (if any).
+ */
+ caption: string | undefined;
}
export interface FileViewerPhotoSwipeDelegate {
@@ -625,8 +629,8 @@ export class FileViewerPhotoSwipe {
html: "<p/>",
onInit: (captionElement, pswp) =>
pswp.on("change", () => {
- const { file } = pswp.currSlide.content.data;
- captionElement.innerText = `${file}`;
+ captionElement.innerText =
+ currentFileAnnotation().caption ?? "";
}),
});
});
diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.ts
index a9ceba491c..44936d9af5 100644
--- a/web/packages/media/file-metadata.ts
+++ b/web/packages/media/file-metadata.ts
@@ -855,3 +855,10 @@ export const fileLocation = (file: EnteFile): Location | undefined => {
return { latitude, longitude };
};
+
+/**
+ * Return the caption, aka "description", (if any) attached to the given
+ * {@link EnteFile}.
+ */
+export const fileCaption = (file: EnteFile): string | undefined =>
+ filePublicMagicMetadata(file)?.caption;