Skip to content

armgit / ente

Public Imported from GitHub
0

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

Caption

Manav Rathi92e33c8c2043
diff --git a/web/packages/gallery/components/FileInfo.tsx b/web/packages/gallery/components/FileInfo.tsx
index 25aaa5bc25..d91f0bd3b7 100644
--- a/web/packages/gallery/components/FileInfo.tsx
+++ b/web/packages/gallery/components/FileInfo.tsx
@@ -55,10 +55,6 @@ import log from "ente-base/log";
import type { Location } from "ente-base/types";
import { CopyButton } from "ente-gallery/components/FileInfoComponents";
import { tagNumericValue, type RawExifTags } from "ente-gallery/services/exif";
-import {
- changeCaption,
- updateExistingFilePubMetadata,
-} from "ente-gallery/services/file";
import { formattedByteSize } from "ente-gallery/utils/units";
import { type EnteFile } from "ente-media/file";
import {
@@ -79,7 +75,10 @@ import {
confirmEnableMapsDialogAttributes,
} from "ente-new/photos/components/utils/dialog";
import { useSettingsSnapshot } from "ente-new/photos/components/utils/use-snapshot";
-import { updateFileFileName } from "ente-new/photos/services/file";
+import {
+ updateFileCaption,
+ updateFileFileName,
+} from "ente-new/photos/services/file";
import {
getAnnotatedFacesForFile,
isMLEnabled,
@@ -179,10 +178,11 @@ export type FileInfoProps = ModalVisibilityProps & {
* This hook allows the file viewer to update the caption it is displaying
* for the given file.
*
- * @param updatedFile The updated file object, containing the updated
- * caption.
+ * @param fileID The ID of the file whose caption was updated.
+ *
+ * @param newCaption The updated value of the file's caption.
*/
- onUpdateCaption: (updatedFile: EnteFile) => void;
+ onUpdateCaption: (fileID: number, newCaption: string) => void;
/**
* Called when the user selects a collection from among the collections that
* the file belongs to.
@@ -286,6 +286,7 @@ export const FileInfo: React.FC<FileInfoProps> = ({
file,
allowEdits,
onNeedsRemoteSync,
+ onFileAndCollectionSyncWithRemote,
onUpdateCaption,
}}
/>
@@ -577,13 +578,18 @@ const EditButton: React.FC<EditButtonProps> = ({ onClick, loading }) => (
type CaptionProps = Pick<
FileInfoProps,
- "file" | "allowEdits" | "onNeedsRemoteSync" | "onUpdateCaption"
+ | "file"
+ | "allowEdits"
+ | "onNeedsRemoteSync"
+ | "onFileAndCollectionSyncWithRemote"
+ | "onUpdateCaption"
>;
const Caption: React.FC<CaptionProps> = ({
file,
allowEdits,
onNeedsRemoteSync,
+ onFileAndCollectionSyncWithRemote,
onUpdateCaption,
}) => {
const [isSaving, setIsSaving] = useState(false);
@@ -600,9 +606,9 @@ const Caption: React.FC<CaptionProps> = ({
if (newCaption == caption) return;
setIsSaving(true);
try {
- const updatedFile = await changeCaption(file, newCaption);
- updateExistingFilePubMetadata(file, updatedFile);
- onUpdateCaption(file);
+ await updateFileCaption(file, newCaption);
+ await onFileAndCollectionSyncWithRemote();
+ onUpdateCaption(file.id, newCaption);
} catch (e) {
log.error("Failed to update caption", e);
setFieldError("caption", t("generic_error"));
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 0e2327d97c..4afdbf8833 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -830,8 +830,14 @@ export const FileViewer: React.FC<FileViewerProps> = ({
// the other attributes of the annotated file currently depend on
// the archive status change.
//
- // - Similar reasoning applies to updates to the file's fileName in
- // the file info panel.
+ // - Similar reasoning applies to updates to the file's file name in
+ // file info panel.
+ //
+ // - For updates to the file's caption in the file info panel we
+ // already need special casing (see `updateItemDataAlt`) to reload
+ // the slide since the PhotoSwipe UI element that displays the
+ // caption needs to be reloaded. So we'll come here in the caption
+ // update case too, but this code then isn't strictly necessary.
return { ...af, file: updatedFile };
});
}, [handleClose, files]);
@@ -896,10 +902,13 @@ export const FileViewer: React.FC<FileViewerProps> = ({
handleMore,
]);
- const handleUpdateCaption = useCallback((updatedFile: EnteFile) => {
- updateItemDataAlt(updatedFile);
- psRef.current!.refreshCurrentSlideContent();
- }, []);
+ const handleUpdateCaption = useCallback(
+ (fileID: number, newCaption: string) => {
+ updateItemDataAlt(fileID, newCaption);
+ psRef.current!.refreshCurrentSlideContent();
+ },
+ [],
+ );
useEffect(updateFullscreenStatus, [updateFullscreenStatus]);
diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.ts
index 23a11fa8da..1611c9e41f 100644
--- a/web/packages/gallery/components/viewer/data-source.ts
+++ b/web/packages/gallery/components/viewer/data-source.ts
@@ -404,12 +404,15 @@ export const forgetItemDataForFileIDIfNeeded = (fileID: number) => {
* Update the alt attribute of the {@link ItemData}, if any, associated with the
* given {@link EnteFile}.
*
- * @param updatedFile The file whose caption was updated.
+ * @param fileID The ID of the file whose {@link alt} attribute we want to
+ * update.
+ *
+ * @param newAlt The new value of the {@link alt} attribute.
*/
-export const updateItemDataAlt = (updatedFile: EnteFile) => {
- const itemData = _state.itemDataByFileID.get(updatedFile.id);
+export const updateItemDataAlt = (fileID: number, newAlt: string) => {
+ const itemData = _state.itemDataByFileID.get(fileID);
if (itemData) {
- itemData.alt = fileCaption(updatedFile);
+ itemData.alt = newAlt;
}
};