π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
hook up
Manav Rathifb7d18e74966
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex aa20f0d9b6..958d8b73d9 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -602,6 +602,11 @@ export const FileViewer: React.FC<FileViewerProps> = ({},[haveUser, favoriteFileIDs, pendingFavoriteUpdates, onToggleFavorite],);+ const isFavoritePending = useCallback(+ ({ file }: FileViewerAnnotatedFile) =>+ !!pendingFavoriteUpdates?.has(file.id),+ [pendingFavoriteUpdates],+ );const toggleFavorite = useCallback(({ file }: FileViewerAnnotatedFile) => {@@ -770,6 +775,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({delegateRef.current = {getFiles,isFavorite,+ isFavoritePending,toggleFavorite,shouldIgnoreKeyboardEvent,performKeyAction,@@ -781,12 +787,14 @@ export const FileViewer: React.FC<FileViewerProps> = ({const delegate = delegateRef.current!;delegate.getFiles = getFiles;delegate.isFavorite = isFavorite;+ delegate.isFavoritePending = isFavoritePending;delegate.toggleFavorite = toggleFavorite;delegate.shouldIgnoreKeyboardEvent = shouldIgnoreKeyboardEvent;delegate.performKeyAction = performKeyAction;}, [getFiles,isFavorite,+ isFavoritePending,toggleFavorite,shouldIgnoreKeyboardEvent,performKeyAction,diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex 00b2c19405..c5a78dcac2 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -41,6 +41,11 @@ export interface FileViewerPhotoSwipeDelegate {* the toggle state of the toggle favorite button for the file.*/isFavorite: (annotatedFile: FileViewerAnnotatedFile) => boolean | undefined;+ /**+ * Return `true` if there is an inflight request to update the favorite+ * status of the file.+ */+ isFavoritePending: (annotatedFile: FileViewerAnnotatedFile) => boolean;/*** Called when the user activates the toggle favorite action on a file.*@@ -609,21 +614,23 @@ export class FileViewerPhotoSwipe {let favoriteButtonElement: HTMLButtonElement | undefined;- /**- * IDs of files for which a there is a favorite update in progress.- */- const pendingFavoriteUpdates = new Set<number>();-const toggleFavorite = async () => {- const af = currentAnnotatedFile();- pendingFavoriteUpdates.add(af.file.id);- updateFavoriteButton();- await delegate.toggleFavorite(af);- pendingFavoriteUpdates.delete(af.file.id);- updateFavoriteButton();+ updateFavoriteButtonIfNeeded();+ await delegate.toggleFavorite(currentAnnotatedFile());+ updateFavoriteButtonIfNeeded();};- const updateFavoriteButton = () => {+ const updateFavoriteButtonIfNeeded = () => {+ const favoriteIconFill = document.getElementById(+ "pswp__icn-favorite-fill",+ );+ if (!favoriteIconFill) {+ // Need a null check since we might've been closed meanwhile on+ // the code path where we're called after the async operation in+ // `toggleFavorite`.+ return;+ }+const button = favoriteButtonElement!;const af = currentAnnotatedFile();@@ -636,20 +643,21 @@ export class FileViewerPhotoSwipe {}// Update the button interactivity based on pending requests.- button.disabled = pendingFavoriteUpdates.has(af.file.id);+ button.disabled = delegate.isFavoritePending(af);// Update the fill visibility based on the favorite status.- const fill = document.getElementById("pswp__icn-favorite-fill");- if (fill) {- // Need a null check since we might've been closed meanwhile.- showIf(fill, !!delegate.isFavorite(af));- }+ showIf(favoriteIconFill, !!delegate.isFavorite(af));};const handleToggleFavorite = () => void toggleFavorite();const handleToggleFavoriteIfEnabled = () => {- if (haveUser) handleToggleFavorite();+ if (+ haveUser &&+ !delegate.isFavoritePending(currentAnnotatedFile())+ ) {+ handleToggleFavorite();+ }};const handleDownload = () => onDownload(currentAnnotatedFile());@@ -761,7 +769,7 @@ export class FileViewerPhotoSwipe {// The cast should be safe (unless there is a// PhotoSwipe bug) since we set isButton to true.buttonElement as HTMLButtonElement;- pswp.on("change", updateFavoriteButton);+ pswp.on("change", updateFavoriteButtonIfNeeded);},onClick: handleToggleFavorite,});