π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
trigger
Manav Rathifb7fe057169a
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex 958d8b73d9..b5729def89 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -343,32 +343,9 @@ export const FileViewer: React.FC<FileViewerProps> = ({const [isFullscreen, setIsFullscreen] = useState(false);- // Callbacks to be invoked (only once) the next time we get an update to the- // `files` or `favoriteFileIDs` props.- //- // The callback is passed the latest values of the `files` prop.- //- // Both of those trace their way back to the same reducer, so they get- // updated in tandem. When we delete files, only the `files` prop gets- // updated, while when we toggle favoriets, only the `favoriteFileIDs` prop- // gets updated.- const [, setOnNextFilesOrFavoritesUpdate] = useState<- ((files: EnteFile[]) => void)[]- >([]);-// If `true`, then we need to trigger a sync with remote when we close.const [, setNeedsSync] = useState(false);- /**- * Add a callback to be fired (only once) the next time we get an update to- * the `files` prop.- */- const awaitNextFilesOrFavoritesUpdate = useCallback(- (cb: (files: EnteFile[]) => void) =>- setOnNextFilesOrFavoritesUpdate((cbs) => cbs.concat(cb)),- [],- );-const handleNeedsRemoteSync = useCallback(() => setNeedsSync(true), []);const handleClose = useCallback(() => {@@ -602,6 +579,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({},[haveUser, favoriteFileIDs, pendingFavoriteUpdates, onToggleFavorite],);+const isFavoritePending = useCallback(({ file }: FileViewerAnnotatedFile) =>!!pendingFavoriteUpdates?.has(file.id),@@ -609,26 +587,11 @@ export const FileViewer: React.FC<FileViewerProps> = ({);const toggleFavorite = useCallback(- ({ file }: FileViewerAnnotatedFile) => {- return new Promise<void>((resolve) => {- // See: [Note: File viewer update and dispatch]- onToggleFavorite!(file)- .then(- () => awaitNextFilesOrFavoritesUpdate(() => resolve()),- (e: unknown) => {- onGenericError(e);- resolve();- },- )- .finally(handleNeedsRemoteSync);- });- },- [- onToggleFavorite,- onGenericError,- awaitNextFilesOrFavoritesUpdate,- handleNeedsRemoteSync,- ],+ ({ file }: FileViewerAnnotatedFile) =>+ onToggleFavorite!(file)+ .catch(onGenericError)+ .finally(handleNeedsRemoteSync),+ [onToggleFavorite, onGenericError, handleNeedsRemoteSync],);const updateFullscreenStatus = useCallback(() => {@@ -848,13 +811,11 @@ export const FileViewer: React.FC<FileViewerProps> = ({return af;});+ }, [handleClose, files]);- // - Used for favorite updates.- setOnNextFilesOrFavoritesUpdate((cbs) => {- cbs.forEach((cb) => cb(files));- return [];- });- }, [handleClose, files, favoriteFileIDs]);+ useEffect(() => {+ psRef.current?.refreshCurrentSlideFavoriteButtonIfNeeded();+ }, [favoriteFileIDs, pendingFavoriteUpdates]);useEffect(() => {if (open) {diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex c5a78dcac2..2cf7116942 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -615,15 +615,22 @@ export class FileViewerPhotoSwipe {let favoriteButtonElement: HTMLButtonElement | undefined;const toggleFavorite = async () => {- updateFavoriteButtonIfNeeded();+ // updateFavoriteButtonIfNeeded();await delegate.toggleFavorite(currentAnnotatedFile());- updateFavoriteButtonIfNeeded();+ // updateFavoriteButtonIfNeeded();};const updateFavoriteButtonIfNeeded = () => {const favoriteIconFill = document.getElementById("pswp__icn-favorite-fill",);+ console.log("updateFavoriteButtonIfNeeded", {+ favoriteIconFill,+ isFavorite: delegate.isFavoritePending(currentAnnotatedFile()),+ isFavoritePending: delegate.isFavoritePending(+ currentAnnotatedFile(),+ ),+ });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@@ -649,6 +656,9 @@ export class FileViewerPhotoSwipe {showIf(favoriteIconFill, !!delegate.isFavorite(af));};+ this.refreshCurrentSlideFavoriteButtonIfNeeded =+ updateFavoriteButtonIfNeeded;+const handleToggleFavorite = () => void toggleFavorite();const handleToggleFavoriteIfEnabled = () => {@@ -1044,6 +1054,15 @@ export class FileViewerPhotoSwipe {this.pswp.refreshSlideContent(this.pswp.currIndex);}}++ /**+ * Refresh the favorite button (if indeed it is visible at all) on the+ * current slide, asking the delegate for the latest state.+ *+ * We do this piecemeal update instead of a full refresh because a full+ * refresh would cause, e.g., the pan and zoom to be reset.+ */+ refreshCurrentSlideFavoriteButtonIfNeeded: () => void;}const videoHTML = (url: string, disableDownload: boolean) => `