Skip to content

armgit / ente

Public Imported from GitHub
0

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

Change both in sync

Manav Rathib851a30c1805
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsx
index 57c4831fd4..8c4164da84 100644
--- a/web/packages/gallery/components/viewer/FileViewer.tsx
+++ b/web/packages/gallery/components/viewer/FileViewer.tsx
@@ -293,36 +293,36 @@ const FileViewer: React.FC<FileViewerProps> = ({
const getFiles = useCallback(() => files, [files]);
- const isFavorite = useMemo(() => {
- return showModifyActions && favoriteFileIDs
- ? (annotatedFile: FileViewerAnnotatedFile): boolean =>
- favoriteFileIDs.has(annotatedFile.file.id)
- : undefined;
+ const [isFavorite, toggleFavorite] = useMemo(() => {
+ if (!showModifyActions || !favoriteFileIDs)
+ return [undefined, undefined];
+
+ const isFavorite = ({ file }: FileViewerAnnotatedFile) =>
+ favoriteFileIDs.has(file.id);
+
+ const toggleFavorite = ({
+ file,
+ annotation,
+ }: FileViewerAnnotatedFile) => {
+ console.log({ file, annotation });
+ // TODO
+ // const isFavorite = annotation.isFavorite;
+ // if (isFavorite === undefined) {
+ // assertionFailed();
+ // return;
+ // }
+
+ // onMarkUnsyncedFavoriteUpdate(file.id, !isFavorite);
+ // void (isFavorite ? removeFromFavorites : addToFavorites)(
+ // file,
+ // ).catch((e: unknown) => {
+ // log.error("Failed to remove favorite", e);
+ // onMarkUnsyncedFavoriteUpdate(file.id, undefined);
+ // });
+ };
+ return [isFavorite, toggleFavorite];
}, [showModifyActions, favoriteFileIDs]);
- const toggleFavorite = useMemo(() => {
- return favoriteFileIDs
- ? ({ file, annotation }: FileViewerAnnotatedFile) => {
- console.log({ file, annotation });
- // TODO
- // const isFavorite = annotation.isFavorite;
- // if (isFavorite === undefined) {
- // assertionFailed();
- // return;
- // }
-
- // onMarkUnsyncedFavoriteUpdate(file.id, !isFavorite);
- // void (isFavorite ? removeFromFavorites : addToFavorites)(
- // file,
- // ).catch((e: unknown) => {
- // log.error("Failed to remove favorite", e);
- // onMarkUnsyncedFavoriteUpdate(file.id, undefined);
- // });
- }
- : undefined;
- // }, [favoriteFileIDs, onMarkUnsyncedFavoriteUpdate]);
- }, [favoriteFileIDs]);
-
// Initial value of delegate.
if (!delegateRef.current) {
delegateRef.current = { getFiles, isFavorite, toggleFavorite };
diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.ts
index 6cfe8f4918..bd418dbb9e 100644
--- a/web/packages/gallery/components/viewer/photoswipe.ts
+++ b/web/packages/gallery/components/viewer/photoswipe.ts
@@ -85,9 +85,7 @@ export interface FileViewerPhotoSwipeDelegate {
* `undefined`. Otherwise the return value determines the toggle state of
* the toggle favorite button for the file.
*/
- isFavorite?: (
- annotatedFile: FileViewerAnnotatedFile,
- ) => boolean | undefined;
+ isFavorite?: (annotatedFile: FileViewerAnnotatedFile) => boolean;
/**
* Called when the user activates the toggle favorite action on a file.
*/