Skip to content

armgit / ente

Public Imported from GitHub
0

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

Stabilize trip album viewer during downloads

Anand Baburajan4f1dbea45bb0
diff --git a/web/apps/photos/src/components/ActiveDownloadStatusNotifications.tsx b/web/apps/photos/src/components/ActiveDownloadStatusNotifications.tsx
new file mode 100644
index 0000000000..78daab7ee0
--- /dev/null
+++ b/web/apps/photos/src/components/ActiveDownloadStatusNotifications.tsx
@@ -0,0 +1,22 @@
+import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
+import { type ComponentProps } from "react";
+import { DownloadStatusNotifications } from "./DownloadStatusNotifications";
+
+type ActiveDownloadStatusNotificationsProps = Omit<
+ ComponentProps<typeof DownloadStatusNotifications>,
+ "saveGroups" | "onRemoveSaveGroup"
+>;
+
+export const ActiveDownloadStatusNotifications: React.FC<
+ ActiveDownloadStatusNotificationsProps
+> = (props) => {
+ const { saveGroups, onRemoveSaveGroup } = useSaveGroups();
+
+ return (
+ <DownloadStatusNotifications
+ saveGroups={saveGroups}
+ onRemoveSaveGroup={onRemoveSaveGroup}
+ {...props}
+ />
+ );
+};
diff --git a/web/apps/photos/src/components/TripLayout/index.tsx b/web/apps/photos/src/components/TripLayout/index.tsx
index 461a803680..cee4133053 100644
--- a/web/apps/photos/src/components/TripLayout/index.tsx
+++ b/web/apps/photos/src/components/TripLayout/index.tsx
@@ -1,8 +1,8 @@
import { Box, styled, useMediaQuery, useTheme } from "@mui/material";
-import { DownloadStatusNotifications } from "components/DownloadStatusNotifications";
+import { ActiveDownloadStatusNotifications } from "components/ActiveDownloadStatusNotifications";
import { useModalVisibility } from "ente-base/components/utils/modal";
import type { PublicAlbumsCredentials } from "ente-base/http";
-import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
+import { useSaveGroupsActions } from "ente-gallery/components/utils/save-groups";
import {
FileViewer,
type FileViewerInitialSidebar,
@@ -88,7 +88,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
const isMobileOrTablet = useMediaQuery(theme.breakpoints.down("md")); // 960px breakpoint for mobile and tablet
// Save groups hook for download progress tracking
- const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
+ const { onAddSaveGroup } = useSaveGroupsActions();
const { show: showPublicFeed, props: publicFeedVisibilityProps } =
useModalVisibility();
@@ -605,11 +605,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
/>
{/* Download progress notifications */}
- <DownloadStatusNotifications
- saveGroups={saveGroups}
- onRemoveSaveGroup={onRemoveSaveGroup}
- fullWidthOnMobile
- />
+ <ActiveDownloadStatusNotifications fullWidthOnMobile />
{/* Public feed sidebar */}
{collection && credentials?.current && collectionKey && (
diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsx
index 06930b284e..5a56cf19ed 100644
--- a/web/apps/photos/src/pages/shared-albums.tsx
+++ b/web/apps/photos/src/pages/shared-albums.tsx
@@ -18,8 +18,8 @@ import {
useMediaQuery,
} from "@mui/material";
import Typography from "@mui/material/Typography";
+import { ActiveDownloadStatusNotifications } from "components/ActiveDownloadStatusNotifications";
import { FeedIcon } from "components/Collections/CollectionHeader";
-import { DownloadStatusNotifications } from "components/DownloadStatusNotifications";
import { type FileListHeaderOrFooter } from "components/FileList";
import { FileListWithViewer } from "components/FileListWithViewer";
import { PublicAlbumSingleFileViewer } from "components/PublicAlbumSingleFileViewer";
@@ -58,7 +58,7 @@ import {
} from "ente-base/origins";
import { FullScreenDropZone } from "ente-gallery/components/FullScreenDropZone";
import {
- useSaveGroups,
+ useSaveGroupsActions,
type AddSaveGroup,
} from "ente-gallery/components/utils/save-groups";
import { type FileViewerInitialSidebar } from "ente-gallery/components/viewer/FileViewer";
@@ -141,7 +141,7 @@ export default function PublicCollectionGallery() {
const isRedirectingToAlbumsAppRef = useRef<boolean>(false);
- const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
+ const { onAddSaveGroup } = useSaveGroupsActions();
const { show: showPublicFeed, props: publicFeedVisibilityProps } =
useModalVisibility();
@@ -613,10 +613,7 @@ export default function PublicCollectionGallery() {
onAddSaveGroup={onAddSaveGroup}
/>
{blockingLoad && <TranslucentLoadingOverlay />}
- <DownloadStatusNotifications
- {...{ saveGroups, onRemoveSaveGroup }}
- fullWidthOnMobile
- />
+ <ActiveDownloadStatusNotifications fullWidthOnMobile />
</>
);
}
@@ -735,10 +732,7 @@ export default function PublicCollectionGallery() {
onShowSessionExpiredDialog={showPublicLinkExpiredMessage}
{...{ dragAndDropFiles }}
/>
- <DownloadStatusNotifications
- {...{ saveGroups, onRemoveSaveGroup }}
- fullWidthOnMobile
- />
+ <ActiveDownloadStatusNotifications fullWidthOnMobile />
{publicCollection && collectionKey.current && (
<PublicFeedSidebar
{...publicFeedVisibilityProps}
diff --git a/web/packages/gallery/components/utils/save-groups.ts b/web/packages/gallery/components/utils/save-groups.ts
index 83fecd16e2..9c068085b6 100644
--- a/web/packages/gallery/components/utils/save-groups.ts
+++ b/web/packages/gallery/components/utils/save-groups.ts
@@ -235,3 +235,14 @@ export const useSaveGroups = () => {
onRemoveSaveGroup: removeSaveGroup,
};
};
+
+/**
+ * Return save-group actions without subscribing to progress updates.
+ *
+ * Use this in components that only need to initiate or dismiss downloads,
+ * otherwise every save progress update will re-render the caller.
+ */
+export const useSaveGroupsActions = () => ({
+ onAddSaveGroup: addSaveGroup,
+ onRemoveSaveGroup: removeSaveGroup,
+});