Skip to content

armgit / ente

Public Imported from GitHub
0

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

Optimize albums public route bundle loading

Anand Baburajan4f0d363dd579
diff --git a/web/apps/albums/src/gallery/components/FullScreenDropZone.tsx b/web/apps/albums/src/gallery/components/FullScreenDropZone.tsx
index caa4445e0c..458444f5ad 100644
--- a/web/apps/albums/src/gallery/components/FullScreenDropZone.tsx
+++ b/web/apps/albums/src/gallery/components/FullScreenDropZone.tsx
@@ -21,7 +21,7 @@ const hasDraggedFiles = (
return false;
};
-interface FullScreenDropZoneProps {
+export interface FullScreenDropZoneProps {
/**
* Optional override to the message show to the user when a drag is in
* progress.
diff --git a/web/apps/albums/src/gallery/components/viewer/lazy.ts b/web/apps/albums/src/gallery/components/viewer/lazy.ts
new file mode 100644
index 0000000000..be337d7dee
--- /dev/null
+++ b/web/apps/albums/src/gallery/components/viewer/lazy.ts
@@ -0,0 +1,16 @@
+import dynamic from "next/dynamic";
+import type { FileViewerProps } from "./FileViewer";
+import type { PublicFeedSidebarProps } from "./PublicFeedSidebar";
+
+export const LazyFileViewer = dynamic<FileViewerProps>(
+ () => import("./FileViewer").then(({ FileViewer }) => FileViewer),
+ { ssr: false },
+);
+
+export const LazyPublicFeedSidebar = dynamic<PublicFeedSidebarProps>(
+ () =>
+ import("./PublicFeedSidebar").then(
+ ({ PublicFeedSidebar }) => PublicFeedSidebar,
+ ),
+ { ssr: false },
+);
diff --git a/web/apps/albums/src/gallery/services/save.ts b/web/apps/albums/src/gallery/services/save.ts
index cef0f003f0..8d160e3cc8 100644
--- a/web/apps/albums/src/gallery/services/save.ts
+++ b/web/apps/albums/src/gallery/services/save.ts
@@ -7,7 +7,7 @@ import type { EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
import { decodeLivePhoto } from "ente-media/live-photo";
-import JSZip from "jszip";
+import type JSZip from "jszip";
import type {
AddSaveGroup,
UpdateSaveGroup,
@@ -24,6 +24,21 @@ interface DownloadLimits {
}
let cachedLimits: DownloadLimits | undefined;
+type JSZipConstructor = new () => JSZip;
+
+let jsZipConstructorPromise: Promise<JSZipConstructor> | undefined;
+
+const createJSZip = async (): Promise<JSZip> => {
+ const JSZipConstructor = await (jsZipConstructorPromise ??= import(
+ "jszip"
+ ).then((module) => {
+ const candidate = (
+ module as unknown as { default?: JSZipConstructor }
+ ).default;
+ return candidate ?? (module as unknown as JSZipConstructor);
+ }));
+ return new JSZipConstructor();
+};
/**
* Get download limits for the current device.
@@ -267,7 +282,7 @@ const downloadAndSave = async (
* the batch size limit is reached.
*/
class ZipBatcher {
- private zip = new JSZip();
+ private zipPromise = createJSZip();
private currentBatchSize = 0;
private currentFileCount = 0;
private batchIndex: number;
@@ -331,7 +346,8 @@ class ZipBatcher {
// Ensure unique file names within the ZIP
const uniqueName = this.getUniqueName(fileName);
this.usedNames.add(uniqueName);
- this.zip.file(uniqueName, data);
+ const zip = await this.zipPromise;
+ zip.file(uniqueName, data);
this.currentBatchSize += size;
this.currentFileCount++;
}
@@ -348,7 +364,8 @@ class ZipBatcher {
private async downloadCurrentBatch(): Promise<void> {
this.onStateChange?.(true, this.batchIndex);
try {
- const zipBlob = await this.zip.generateAsync({ type: "blob" });
+ const zip = await this.zipPromise;
+ const zipBlob = await zip.generateAsync({ type: "blob" });
const fileLabel =
this.currentFileCount === 1
? "1 file"
@@ -369,7 +386,7 @@ class ZipBatcher {
}
// Reset for next batch
- this.zip = new JSZip();
+ this.zipPromise = createJSZip();
this.currentBatchSize = 0;
this.currentFileCount = 0;
this.usedNames.clear();
diff --git a/web/apps/albums/src/pages/_app.tsx b/web/apps/albums/src/pages/_app.tsx
index b6f631bde7..9aebfacbb5 100644
--- a/web/apps/albums/src/pages/_app.tsx
+++ b/web/apps/albums/src/pages/_app.tsx
@@ -1,16 +1,18 @@
import "@fontsource-variable/inter";
import { CssBaseline } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
+import {
+ LazyAttributedMiniDialog,
+ LazyNotification,
+} from "@/public-album/components/lazy-ui";
import { useNotification } from "@/public-album/hooks/useNotification";
import { staticAppTitle } from "ente-base/app";
import { CustomHeadAlbums } from "ente-base/components/Head";
import { LoadingIndicator } from "ente-base/components/loaders";
-import { AttributedMiniDialog } from "ente-base/components/MiniDialog";
import { useAttributedMiniDialog } from "ente-base/components/utils/dialog";
import { useSetupI18n } from "ente-base/components/utils/hooks-app";
import { photosTheme } from "ente-base/components/utils/theme";
import { BaseContext, deriveBaseContext } from "ente-base/context";
-import { Notification } from "ente-new/photos/components/Notification";
import { ThemedLoadingBar } from "ente-new/photos/components/ThemedLoadingBar";
import { useLoadingBar } from "ente-new/photos/components/utils/use-loading-bar";
import { PhotosAppContext } from "ente-new/photos/types/context";
@@ -62,8 +64,10 @@ const App: React.FC<AlbumsAppProps> = ({ Component, pageProps }) => {
<CssBaseline enableColorScheme />
<ThemedLoadingBar ref={loadingBarRef} />
- <AttributedMiniDialog {...miniDialogProps} />
- <Notification {...notificationProps} />
+ {miniDialogProps.open && (
+ <LazyAttributedMiniDialog {...miniDialogProps} />
+ )}
+ {notificationProps.open && <LazyNotification {...notificationProps} />}
<BaseContext value={baseContext}>
<PhotosAppContext value={appContext}>
diff --git a/web/apps/albums/src/pages/index.tsx b/web/apps/albums/src/pages/index.tsx
index 1522fe348c..a1a78cbf47 100644
--- a/web/apps/albums/src/pages/index.tsx
+++ b/web/apps/albums/src/pages/index.tsx
@@ -22,9 +22,9 @@ import { ActiveDownloadStatusNotifications } from "@/public-album/components/Act
import { FeedIcon } from "@/public-album/components/Collections/FeedIcon";
import { type FileListHeaderOrFooter } from "@/public-album/components/FileList";
import { FileListWithViewer } from "@/public-album/components/FileListWithViewer";
-import { PublicAlbumSingleFileViewer } from "@/public-album/components/PublicAlbumSingleFileViewer";
-import { TripLayout } from "@/public-album/components/TripLayout";
-import { Upload } from "@/public-album/components/Upload";
+import type { PublicAlbumSingleFileViewerProps } from "@/public-album/components/PublicAlbumSingleFileViewer";
+import type { TripLayoutProps } from "@/public-album/components/TripLayout";
+import type { UploadProps } from "@/public-album/components/Upload";
import { SpacedRow, Stack100vhCenter } from "ente-base/components/containers";
import { EnteLogo } from "ente-base/components/EnteLogo";
import {
@@ -34,10 +34,6 @@ import {
import type { ButtonishProps } from "ente-base/components/mui";
import { FocusVisibleButton } from "ente-base/components/mui/FocusVisibleButton";
import { NavbarBase } from "ente-base/components/Navbar";
-import {
- SingleInputForm,
- type SingleInputFormProps,
-} from "ente-base/components/SingleInputForm";
import { useIsSmallWidth } from "ente-base/components/utils/hooks";
import { useModalVisibility } from "ente-base/components/utils/modal";
import { useBaseContext } from "ente-base/context";
@@ -53,63 +49,86 @@ import {
isOfficialAlbumsApp,
photosAppOrigin,
} from "ente-base/origins";
-import { FullScreenDropZone } from "@/gallery/components/FullScreenDropZone";
+import type { FullScreenDropZoneProps } from "@/gallery/components/FullScreenDropZone";
import {
useSaveGroupsActions,
type AddSaveGroup,
} from "@/gallery/components/utils/save-groups";
import { type FileViewerInitialSidebar } from "@/gallery/components/viewer/FileViewer";
-import {
- PublicFeedSidebar,
- type PublicFeedItemClickInfo,
-} from "@/gallery/components/viewer/PublicFeedSidebar";
+import { type PublicFeedItemClickInfo } from "@/gallery/components/viewer/PublicFeedSidebar";
+import { LazyPublicFeedSidebar } from "@/gallery/components/viewer/lazy";
import { downloadManager } from "@/gallery/services/download";
-import {
- downloadAndSaveCollectionFiles,
- downloadAndSaveFiles,
-} from "@/gallery/services/save";
-import { extractCollectionKeyFromShareURL } from "@/gallery/services/share";
-import { updateShouldDisableCFUploadProxy } from "@/gallery/services/upload";
import { sortFiles } from "@/gallery/utils/file";
import type { Collection } from "ente-media/collection";
import { type EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
-import {
- removePublicCollectionAccessTokenJWT,
- removePublicCollectionByKey,
- savedPublicCollectionAccessTokenJWT,
- savedPublicCollectionByKey,
- savedPublicCollectionFiles,
- savePublicCollectionAccessTokenJWT,
-} from "ente-new/albums/services/public-albums-fdb";
-import {
- pullCollection,
- pullPublicCollectionFiles,
- removePublicCollectionFileData,
- verifyPublicAlbumPassword,
-} from "ente-new/albums/services/public-collection";
import {
GalleryItemsHeaderAdapter,
GalleryItemsSummary,
} from "ente-new/photos/components/gallery/ListHeader";
-import { Notification } from "ente-new/photos/components/Notification";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { usePhotosAppContext } from "ente-new/photos/types/context";
-import { useJoinAlbum } from "@/public-album/hooks/useJoinAlbum";
import { t } from "i18next";
+import dynamic from "next/dynamic";
import { useRouter } from "next/router";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { type FileWithPath } from "react-dropzone";
import {
- AccountsPageContents,
- AccountsPageTitle,
-} from "@/public-album/components/AccountsPage";
-import { uploadManager } from "@/public-album/services/upload-manager";
+ type ComponentType,
+ type PropsWithChildren,
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+import { type FileWithPath } from "react-dropzone";
+import { LazyNotification } from "@/public-album/components/lazy-ui";
+import type { PasswordUnlockScreenProps } from "@/public-album/components/PasswordUnlockScreen";
import { getSelectedFiles, type SelectedState } from "@/public-album/utils/file";
import { getEnteURL } from "@/public-album/utils/public-album";
import { quickLinkDateRangeForFiles } from "@/public-album/utils/quick-link";
+const LazyPublicAlbumSingleFileViewer =
+ dynamic<PublicAlbumSingleFileViewerProps>(
+ () =>
+ import("@/public-album/components/PublicAlbumSingleFileViewer").then(
+ ({ PublicAlbumSingleFileViewer }) => PublicAlbumSingleFileViewer,
+ ),
+ { ssr: false, loading: () => <LoadingIndicator /> },
+ );
+
+const LazyTripLayout = dynamic<TripLayoutProps>(
+ () =>
+ import("@/public-album/components/TripLayout").then(
+ ({ TripLayout }) => TripLayout,
+ ),
+ { ssr: false, loading: () => <LoadingIndicator /> },
+);
+
+const LazyUpload = dynamic<UploadProps>(
+ () => import("@/public-album/components/Upload").then(({ Upload }) => Upload),
+ { ssr: false },
+);
+
+const LazyPasswordUnlockScreen = dynamic<PasswordUnlockScreenProps>(
+ () =>
+ import("@/public-album/components/PasswordUnlockScreen").then(
+ ({ PasswordUnlockScreen }) => PasswordUnlockScreen,
+ ),
+ { ssr: false, loading: () => <LoadingIndicator /> },
+);
+
+const loadPublicAlbumsFDB = () =>
+ import("ente-new/albums/services/public-albums-fdb");
+
+const loadPublicCollectionService = () =>
+ import("ente-new/albums/services/public-collection");
+
+const loadShareService = () => import("@/gallery/services/share");
+
+const loadJoinPublicAlbumRedirect = () =>
+ import("@/public-album/services/join-public-album-redirect");
+
export default function PublicCollectionGallery() {
const { showMiniDialog, onGenericError } = useBaseContext();
const { showLoadingBar, hideLoadingBar } = usePhotosAppContext();
@@ -126,6 +145,8 @@ export default function PublicCollectionGallery() {
const [uploadTypeSelectorView, setUploadTypeSelectorView] = useState(false);
const [blockingLoad, setBlockingLoad] = useState(false);
const [shouldDisableDropzone, setShouldDisableDropzone] = useState(false);
+ const [isUploadInProgress, setIsUploadInProgress] = useState(false);
+ const [shouldRenderUpload, setShouldRenderUpload] = useState(false);
const [dragAndDropFiles, setDragAndDropFiles] = useState<FileWithPath[]>(
[],
);
@@ -233,6 +254,17 @@ export default function PublicCollectionGallery() {
try {
const currentURL = new URL(window.location.href);
const t = currentURL.searchParams.get("t");
+ const [
+ { extractCollectionKeyFromShareURL },
+ {
+ savedPublicCollectionAccessTokenJWT,
+ savedPublicCollectionByKey,
+ savedPublicCollectionFiles,
+ },
+ ] = await Promise.all([
+ loadShareService(),
+ loadPublicAlbumsFDB(),
+ ]);
const ck = await extractCollectionKeyFromShareURL(currentURL);
if (!t && !ck) {
// Only redirect to ente.io if this is NOT a custom/self-hosted instance
@@ -264,8 +296,6 @@ export default function PublicCollectionGallery() {
}
credentials.current = { accessToken, accessTokenJWT };
downloadManager.setPublicAlbumsCredentials(credentials.current);
- // Update the CF proxy flag, but we don't need to block on it.
- void updateShouldDisableCFUploadProxy();
await publicAlbumsRemotePull();
} finally {
if (
@@ -283,6 +313,25 @@ export default function PublicCollectionGallery() {
const downloadEnabled =
publicCollection?.publicURLs[0]?.enableDownload ?? true;
+ const collectEnabled = publicCollection?.publicURLs[0]?.enableCollect ?? false;
+
+ useEffect(() => {
+ if (!collectEnabled) return;
+ void import("@/gallery/services/upload").then(
+ ({ updateShouldDisableCFUploadProxy }) =>
+ updateShouldDisableCFUploadProxy(),
+ );
+ }, [collectEnabled]);
+
+ useEffect(() => {
+ if (
+ uploadTypeSelectorView ||
+ dragAndDropFiles.length > 0 ||
+ isUploadInProgress
+ ) {
+ setShouldRenderUpload(true);
+ }
+ }, [dragAndDropFiles.length, isUploadInProgress, uploadTypeSelectorView]);
/**
* Pull the latest data related to the public album from remote, updating
@@ -293,6 +342,17 @@ export default function PublicCollectionGallery() {
showLoadingBar();
setLoading(true);
try {
+ const [
+ {
+ pullCollection,
+ pullPublicCollectionFiles,
+ removePublicCollectionFileData,
+ },
+ { removePublicCollectionAccessTokenJWT },
+ ] = await Promise.all([
+ loadPublicCollectionService(),
+ loadPublicAlbumsFDB(),
+ ]);
const { collection } = await pullCollection(
accessToken,
collectionKey.current!,
@@ -364,6 +424,13 @@ export default function PublicCollectionGallery() {
isHTTPErrorWithStatus(e, 410) ||
isHTTPErrorWithStatus(e, 429)
) {
+ const [
+ { removePublicCollectionFileData },
+ { removePublicCollectionByKey },
+ ] = await Promise.all([
+ loadPublicCollectionService(),
+ loadPublicAlbumsFDB(),
+ ]);
setErrorMessage(
isHTTPErrorWithStatus(e, 429)
? t("link_request_limit_exceeded")
@@ -394,20 +461,38 @@ export default function PublicCollectionGallery() {
setTimeout(hideLoadingBar, 0);
}, [showLoadingBar, hideLoadingBar]);
- // Join album handler for use in file viewer's public like modal
- const { handleJoinAlbum } = useJoinAlbum({
- publicCollection,
- accessToken: credentials.current?.accessToken,
- collectionKey: collectionKey.current,
- credentials,
- });
+ const handleJoinAlbum = useCallback(() => {
+ const accessToken = credentials.current?.accessToken;
+ const currentCollectionKey = collectionKey.current;
+
+ if (!publicCollection || !accessToken || !currentCollectionKey) {
+ return;
+ }
+
+ void loadJoinPublicAlbumRedirect().then(
+ ({ joinPublicAlbumViaRedirect }) =>
+ joinPublicAlbumViaRedirect({
+ publicCollection,
+ accessToken,
+ collectionKey: currentCollectionKey,
+ credentials,
+ }),
+ );
+ }, [publicCollection]);
- const handleSubmitPassword: SingleInputFormProps["onSubmit"] = async (
+ const handleSubmitPassword: PasswordUnlockScreenProps["onSubmit"] = async (
password,
setFieldError,
) => {
try {
const accessToken = credentials.current!.accessToken;
+ const [
+ { verifyPublicAlbumPassword },
+ { savePublicCollectionAccessTokenJWT },
+ ] = await Promise.all([
+ import("@/public-album/services/verify-public-album-password"),
+ loadPublicAlbumsFDB(),
+ ]);
const accessTokenJWT = await verifyPublicAlbumPassword(
publicCollection!.publicURLs[0]!,
password,
@@ -447,6 +532,9 @@ export default function PublicCollectionGallery() {
const downloadFilesHelper = async () => {
try {
+ const { downloadAndSaveFiles } = await import(
+ "@/gallery/services/save"
+ );
const selectedFiles = getSelectedFiles(selected, publicFiles!);
const singleFile =
selectedFiles.length === 1 ? selectedFiles[0] : undefined;
@@ -462,10 +550,12 @@ export default function PublicCollectionGallery() {
};
const onAddPhotos = useMemo(() => {
- return publicCollection?.publicURLs[0]?.enableCollect
- ? () => setUploadTypeSelectorView(true)
- : undefined;
- }, [publicCollection]);
+ if (!collectEnabled) return undefined;
+ return () => {
+ setShouldRenderUpload(true);
+ setUploadTypeSelectorView(true);
+ };
+ }, [collectEnabled]);
const closeUploadTypeSelectorView = () => {
setUploadTypeSelectorView(false);
@@ -474,7 +564,11 @@ export default function PublicCollectionGallery() {
const commentsEnabled =
publicCollection?.publicURLs[0]?.enableComment ?? false;
const joinEnabled = publicCollection?.publicURLs[0]?.enableJoin ?? false;
- const addPhotosEnabled = !!onAddPhotos;
+ const addPhotosEnabled = collectEnabled;
+ const handleDrop = useCallback((files: FileWithPath[]) => {
+ setShouldRenderUpload(true);
+ setDragAndDropFiles(files);
+ }, []);
const hasSelection = selected.count > 0;
const isMobileHeaderLayout = useMediaQuery("(width < 720px)");
@@ -497,6 +591,7 @@ export default function PublicCollectionGallery() {
onShowFeed: commentsEnabled
? showPublicFeed
: undefined,
+ addPhotosDisabled: isUploadInProgress,
hasSelection,
}}
/>
@@ -512,6 +607,7 @@ export default function PublicCollectionGallery() {
showPublicFeed,
commentsEnabled,
onAddPhotos,
+ isUploadInProgress,
hasSelection,
fileListHeaderHeightForViewport,
],
@@ -543,26 +639,7 @@ export default function PublicCollectionGallery() {
</Stack100vhCenter>
);
} else if (isPasswordProtected && !credentials.current?.accessTokenJWT) {
- return (
- <AccountsPageContents>
- <AccountsPageTitle>{t("password")}</AccountsPageTitle>
- <Stack>
- <Typography
- variant="small"
- sx={{ color: "text.muted", mb: 2 }}
- >
- {t("link_password_description")}
- </Typography>
- <SingleInputForm
- inputType="password"
- label={t("password")}
- submitButtonColor="primary"
- submitButtonTitle={t("unlock")}
- onSubmit={handleSubmitPassword}
- />
- </Stack>
- </AccountsPageContents>
- );
+ return <LazyPasswordUnlockScreen onSubmit={handleSubmitPassword} />;
} else if (!publicFiles || !credentials.current) {
return (
<Stack100vhCenter>
@@ -584,7 +661,7 @@ export default function PublicCollectionGallery() {
if (shouldShowSingleFileViewer) {
return (
<>
- <PublicAlbumSingleFileViewer
+ <LazyPublicAlbumSingleFileViewer
file={publicFiles[0]!}
publicAlbumsCredentials={credentials.current}
collectionKey={collectionKey.current!}
@@ -601,14 +678,10 @@ export default function PublicCollectionGallery() {
);
}
- return (
- <FullScreenDropZone
- disabled={shouldDisableDropzone}
- onDrop={setDragAndDropFiles}
- message={t("upload_dropzone_hint_public_album")}
- >
+ const content = (
+ <>
{layout === "trip" ? (
- <TripLayout
+ <LazyTripLayout
files={publicFiles}
collection={publicCollection}
onAddPhotos={onAddPhotos}
@@ -648,24 +721,15 @@ export default function PublicCollectionGallery() {
<Stack direction="row" spacing={2}>
<SecondaryActionButton
onAddPhotos={onAddPhotos}
+ addPhotosDisabled={isUploadInProgress}
enableJoin={joinEnabled}
- publicCollection={publicCollection}
- accessToken={
- credentials.current.accessToken
- }
- collectionKey={collectionKey.current}
- credentials={credentials}
+ onJoinAlbum={handleJoinAlbum}
/>
<PrimaryActionButton
showJoinAsPrimary={
addPhotosEnabled && joinEnabled
}
- publicCollection={publicCollection}
- accessToken={
- credentials.current.accessToken
- }
- collectionKey={collectionKey.current}
- credentials={credentials}
+ onJoinAlbum={handleJoinAlbum}
/>
</Stack>
</SpacedRow>
@@ -699,21 +763,26 @@ export default function PublicCollectionGallery() {
</>
)}
{blockingLoad && <TranslucentLoadingOverlay />}
- <Upload
- publicAlbumsCredentials={credentials.current}
- uploadCollection={publicCollection}
- setLoading={setBlockingLoad}
- setShouldDisableDropzone={setShouldDisableDropzone}
- uploadTypeSelectorView={uploadTypeSelectorView}
- onRemotePull={publicAlbumsRemotePull}
- onUploadFile={handleUploadFile}
- closeUploadTypeSelector={closeUploadTypeSelectorView}
- onShowSessionExpiredDialog={showPublicLinkExpiredMessage}
- {...{ dragAndDropFiles }}
- />
+ {collectEnabled && shouldRenderUpload && (
+ <LazyUpload
+ publicAlbumsCredentials={credentials.current}
+ uploadCollection={publicCollection}
+ setLoading={setBlockingLoad}
+ setShouldDisableDropzone={setShouldDisableDropzone}
+ uploadTypeSelectorView={uploadTypeSelectorView}
+ onRemotePull={publicAlbumsRemotePull}
+ onUploadFile={handleUploadFile}
+ closeUploadTypeSelector={closeUploadTypeSelectorView}
+ onShowSessionExpiredDialog={showPublicLinkExpiredMessage}
+ onUploadInProgressChange={setIsUploadInProgress}
+ {...{ dragAndDropFiles }}
+ />
+ )}
<ActiveDownloadStatusNotifications fullWidthOnMobile />
- {publicCollection && collectionKey.current && (
- <PublicFeedSidebar
+ {publicFeedVisibilityProps.open &&
+ publicCollection &&
+ collectionKey.current && (
+ <LazyPublicFeedSidebar
{...publicFeedVisibilityProps}
files={publicFiles}
credentials={credentials.current}
@@ -721,7 +790,18 @@ export default function PublicCollectionGallery() {
onItemClick={handleFeedItemClick}
/>
)}
- </FullScreenDropZone>
+ </>
+ );
+
+ return (
+ <LazyCollectDropZone
+ enabled={collectEnabled}
+ disabled={shouldDisableDropzone}
+ onDrop={handleDrop}
+ message={t("upload_dropzone_hint_public_album")}
+ >
+ {content}
+ </LazyCollectDropZone>
);
}
@@ -742,6 +822,45 @@ const normalizedPublicAlbumLayout = (layout: string | undefined) => {
return "masonry";
};
+type LazyCollectDropZoneProps = PropsWithChildren<
+ {
+ enabled: boolean;
+ } & Pick<FullScreenDropZoneProps, "disabled" | "message" | "onDrop">
+>;
+
+const LazyCollectDropZone: React.FC<LazyCollectDropZoneProps> = ({
+ enabled,
+ children,
+ ...props
+}) => {
+ const [DropZoneComponent, setDropZoneComponent] =
+ useState<
+ ComponentType<PropsWithChildren<FullScreenDropZoneProps>> | null
+ >(null);
+
+ useEffect(() => {
+ if (!enabled || DropZoneComponent) return;
+
+ let isCancelled = false;
+ void import("@/gallery/components/FullScreenDropZone").then(
+ ({ FullScreenDropZone }) => {
+ if (isCancelled) return;
+ setDropZoneComponent(() => FullScreenDropZone);
+ },
+ );
+
+ return () => {
+ isCancelled = true;
+ };
+ }, [DropZoneComponent, enabled]);
+
+ if (!enabled || !DropZoneComponent) {
+ return <>{children}</>;
+ }
+
+ return <DropZoneComponent {...props}>{children}</DropZoneComponent>;
+};
+
const EnteLogoLink = styled("a")(({ theme }) => ({
// Remove the excess space at the top.
svg: { verticalAlign: "middle" },
@@ -759,8 +878,12 @@ const GreenButton = styled(Button)(() => ({
const navbarActionButtonSx = { borderRadius: "16px", paddingBlock: "11px" };
-const AddPhotosButton: React.FC<ButtonishProps> = ({ onClick }) => {
- const disabled = uploadManager.isUploadInProgress();
+type AddPhotosButtonProps = ButtonishProps & { disabled?: boolean };
+
+const AddPhotosButton: React.FC<AddPhotosButtonProps> = ({
+ onClick,
+ disabled,
+}) => {
const isSmallWidth = useIsSmallWidth();
return (
@@ -786,33 +909,16 @@ const AddPhotosButton: React.FC<ButtonishProps> = ({ onClick }) => {
interface PrimaryActionButtonProps {
/** If true, shows "Join Album" as the primary action */
showJoinAsPrimary?: boolean;
- /** Collection to join (required if showJoinAsPrimary is true) */
- publicCollection?: Collection;
- /** Access token for the public link */
- accessToken?: string;
- /** Collection key from URL (base64 encoded) */
- collectionKey?: string;
- /** Credentials ref for JWT token access */
- credentials?: React.RefObject<PublicAlbumsCredentials | undefined>;
+ onJoinAlbum?: () => void;
}
const PrimaryActionButton: React.FC<PrimaryActionButtonProps> = ({
showJoinAsPrimary,
- publicCollection,
- accessToken,
- collectionKey,
- credentials,
+ onJoinAlbum,
}) => {
- const { handleJoinAlbum } = useJoinAlbum({
- publicCollection,
- accessToken,
- collectionKey,
- credentials,
- });
-
if (showJoinAsPrimary) {
return (
- <GreenButton color="accent" onClick={handleJoinAlbum}>
+ <GreenButton color="accent" onClick={onJoinAlbum}>
{t("join_album")}
</GreenButton>
);
@@ -831,30 +937,24 @@ const PrimaryActionButton: React.FC<PrimaryActionButtonProps> = ({
interface SecondaryActionButtonProps {
onAddPhotos?: () => void;
+ addPhotosDisabled?: boolean;
enableJoin?: boolean;
- publicCollection?: Collection;
- accessToken?: string;
- collectionKey?: string;
- credentials?: React.RefObject<PublicAlbumsCredentials | undefined>;
+ onJoinAlbum?: () => void;
}
const SecondaryActionButton: React.FC<SecondaryActionButtonProps> = ({
onAddPhotos,
+ addPhotosDisabled,
enableJoin,
- publicCollection,
- accessToken,
- collectionKey,
- credentials,
+ onJoinAlbum,
}) => {
- const { handleJoinAlbum } = useJoinAlbum({
- publicCollection,
- accessToken,
- collectionKey,
- credentials,
- });
-
if (onAddPhotos) {
- return <AddPhotosButton onClick={onAddPhotos} />;
+ return (
+ <AddPhotosButton
+ onClick={onAddPhotos}
+ disabled={addPhotosDisabled}
+ />
+ );
}
if (enableJoin) {
@@ -862,7 +962,7 @@ const SecondaryActionButton: React.FC<SecondaryActionButtonProps> = ({
<FocusVisibleButton
color="secondary"
sx={navbarActionButtonSx}
- onClick={handleJoinAlbum}
+ onClick={onJoinAlbum}
>
{t("join_album")}
</FocusVisibleButton>
@@ -928,6 +1028,7 @@ interface FileListHeaderProps {
onAddSaveGroup: AddSaveGroup;
onAddPhotos?: () => void;
onShowFeed?: () => void;
+ addPhotosDisabled: boolean;
hasSelection: boolean;
}
@@ -956,10 +1057,10 @@ const FileListHeader: React.FC<FileListHeaderProps> = ({
onAddSaveGroup,
onAddPhotos,
onShowFeed,
+ addPhotosDisabled,
hasSelection,
}) => {
const [showCopiedMessage, setShowCopiedMessage] = useState(false);
- const addPhotosDisabled = uploadManager.isUploadInProgress();
const memoriesDateRange = useMemo(() => {
return quickLinkDateRangeForFiles(publicFiles);
@@ -969,14 +1070,18 @@ const FileListHeader: React.FC<FileListHeaderProps> = ({
memoriesDateRange !== undefined &&
publicCollection.name === memoriesDateRange;
- const downloadAllFiles = () =>
- downloadAndSaveCollectionFiles(
- publicCollection.name,
- publicCollection.id,
- publicFiles,
- undefined,
- onAddSaveGroup,
+ const downloadAllFiles = () => {
+ void import("@/gallery/services/save").then(
+ ({ downloadAndSaveCollectionFiles }) =>
+ downloadAndSaveCollectionFiles(
+ publicCollection.name,
+ publicCollection.id,
+ publicFiles,
+ undefined,
+ onAddSaveGroup,
+ ),
);
+ };
const handleShare = async () => {
if (typeof window === "undefined") return;
@@ -1107,16 +1212,18 @@ const FileListHeader: React.FC<FileListHeaderProps> = ({
</Stack>
</SpacedRow>
</GalleryItemsHeaderAdapter>
- <Notification
- open={showCopiedMessage}
- onClose={() => setShowCopiedMessage(false)}
- horizontal="left"
- attributes={{
- color: "secondary",
- startIcon: <CheckIcon />,
- title: "Copied!",
- }}
- />
+ {showCopiedMessage && (
+ <LazyNotification
+ open={showCopiedMessage}
+ onClose={() => setShowCopiedMessage(false)}
+ horizontal="left"
+ attributes={{
+ color: "secondary",
+ startIcon: <CheckIcon />,
+ title: "Copied!",
+ }}
+ />
+ )}
</>
);
};
diff --git a/web/apps/albums/src/public-album/components/ActiveDownloadStatusNotifications.tsx b/web/apps/albums/src/public-album/components/ActiveDownloadStatusNotifications.tsx
index 93e01bc4e8..a70f2daaba 100644
--- a/web/apps/albums/src/public-album/components/ActiveDownloadStatusNotifications.tsx
+++ b/web/apps/albums/src/public-album/components/ActiveDownloadStatusNotifications.tsx
@@ -1,9 +1,18 @@
import { useSaveGroups } from "@/gallery/components/utils/save-groups";
-import { type ComponentProps } from "react";
-import { DownloadStatusNotifications } from "./DownloadStatusNotifications";
+import dynamic from "next/dynamic";
+import { type DownloadStatusNotificationsProps } from "./DownloadStatusNotifications";
+
+const LazyDownloadStatusNotifications =
+ dynamic<DownloadStatusNotificationsProps>(
+ () =>
+ import("./DownloadStatusNotifications").then(
+ ({ DownloadStatusNotifications }) => DownloadStatusNotifications,
+ ),
+ { ssr: false },
+ );
type ActiveDownloadStatusNotificationsProps = Omit<
- ComponentProps<typeof DownloadStatusNotifications>,
+ DownloadStatusNotificationsProps,
"saveGroups" | "onRemoveSaveGroup"
>;
@@ -12,8 +21,12 @@ export const ActiveDownloadStatusNotifications: React.FC<
> = (props) => {
const { saveGroups, onRemoveSaveGroup } = useSaveGroups();
+ if (!saveGroups.length) {
+ return null;
+ }
+
return (
- <DownloadStatusNotifications
+ <LazyDownloadStatusNotifications
saveGroups={saveGroups}
onRemoveSaveGroup={onRemoveSaveGroup}
{...props}
diff --git a/web/apps/albums/src/public-album/components/DownloadStatusNotifications.tsx b/web/apps/albums/src/public-album/components/DownloadStatusNotifications.tsx
index 9f90eedb3d..dda287bfb2 100644
--- a/web/apps/albums/src/public-album/components/DownloadStatusNotifications.tsx
+++ b/web/apps/albums/src/public-album/components/DownloadStatusNotifications.tsx
@@ -34,7 +34,7 @@ const truncateAlbumName = (name: string): string => {
return name.slice(0, MAX_ALBUM_NAME_LENGTH) + "...";
};
-interface DownloadStatusNotificationsProps {
+export interface DownloadStatusNotificationsProps {
/**
* A list of user-initiated downloads for which a status should be shown.
*
diff --git a/web/apps/albums/src/public-album/components/FileListWithViewer.tsx b/web/apps/albums/src/public-album/components/FileListWithViewer.tsx
index 5ee7e14fc8..202168d0ed 100644
--- a/web/apps/albums/src/public-album/components/FileListWithViewer.tsx
+++ b/web/apps/albums/src/public-album/components/FileListWithViewer.tsx
@@ -3,15 +3,14 @@ import { isSameDay } from "ente-base/date";
import { formattedDate } from "ente-base/i18n-date";
import type { AddSaveGroup } from "@/gallery/components/utils/save-groups";
import {
- FileViewer,
+ type FileViewerProps,
type FileViewerInitialSidebar,
} from "@/gallery/components/viewer/FileViewer";
-import { downloadAndSaveFiles } from "@/gallery/services/save";
+import { LazyFileViewer } from "@/gallery/components/viewer/lazy";
import type { EnteFile } from "ente-media/file";
import { fileCreationTime, fileFileName } from "ente-media/file-metadata";
import { t } from "i18next";
import {
- type ComponentProps,
useCallback,
useEffect,
useMemo,
@@ -63,7 +62,7 @@ export type FileListWithViewerProps = {
| "activeCollectionID"
> &
Pick<
- ComponentProps<typeof FileViewer>,
+ FileViewerProps,
| "publicAlbumsCredentials"
| "collectionKey"
| "onJoinAlbum"
@@ -144,11 +143,22 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
}, []);
const handleDownload = useCallback(
- (file: EnteFile) =>
- downloadAndSaveFiles([file], fileFileName(file), onAddSaveGroup),
+ async (file: EnteFile) => {
+ const { downloadAndSaveFiles } = await import(
+ "@/gallery/services/save"
+ );
+ return downloadAndSaveFiles(
+ [file],
+ fileFileName(file),
+ onAddSaveGroup,
+ );
+ },
[onAddSaveGroup],
);
+ const shouldRenderFileViewer =
+ openFileViewer || pendingFileIndex !== undefined;
+
return (
<Container>
<AutoSizer>
@@ -168,24 +178,26 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({
/>
)}
</AutoSizer>
- <FileViewer
- open={openFileViewer}
- onClose={handleCloseFileViewerInternal}
- initialIndex={currentIndex}
- initialSidebar={initialSidebar}
- highlightCommentID={highlightCommentID}
- disableDownload={!enableDownload}
- {...{
- files,
- publicAlbumsCredentials,
- collectionKey,
- onJoinAlbum,
- enableComment,
- enableJoin,
- }}
- onDownload={handleDownload}
- activeCollectionID={activeCollectionID}
- />
+ {shouldRenderFileViewer && (
+ <LazyFileViewer
+ open={openFileViewer}
+ onClose={handleCloseFileViewerInternal}
+ initialIndex={currentIndex}
+ initialSidebar={initialSidebar}
+ highlightCommentID={highlightCommentID}
+ disableDownload={!enableDownload}
+ {...{
+ files,
+ publicAlbumsCredentials,
+ collectionKey,
+ onJoinAlbum,
+ enableComment,
+ enableJoin,
+ }}
+ onDownload={handleDownload}
+ activeCollectionID={activeCollectionID}
+ />
+ )}
</Container>
);
};
diff --git a/web/apps/albums/src/public-album/components/PasswordUnlockScreen.tsx b/web/apps/albums/src/public-album/components/PasswordUnlockScreen.tsx
new file mode 100644
index 0000000000..f880ac2d8e
--- /dev/null
+++ b/web/apps/albums/src/public-album/components/PasswordUnlockScreen.tsx
@@ -0,0 +1,34 @@
+import { Stack, Typography } from "@mui/material";
+import {
+ SingleInputForm,
+ type SingleInputFormProps,
+} from "ente-base/components/SingleInputForm";
+import { t } from "i18next";
+import {
+ AccountsPageContents,
+ AccountsPageTitle,
+} from "@/public-album/components/AccountsPage";
+
+export interface PasswordUnlockScreenProps {
+ onSubmit: SingleInputFormProps["onSubmit"];
+}
+
+export const PasswordUnlockScreen: React.FC<PasswordUnlockScreenProps> = ({
+ onSubmit,
+}) => (
+ <AccountsPageContents>
+ <AccountsPageTitle>{t("password")}</AccountsPageTitle>
+ <Stack>
+ <Typography variant="small" sx={{ color: "text.muted", mb: 2 }}>
+ {t("link_password_description")}
+ </Typography>
+ <SingleInputForm
+ inputType="password"
+ label={t("password")}
+ submitButtonColor="primary"
+ submitButtonTitle={t("unlock")}
+ onSubmit={onSubmit}
+ />
+ </Stack>
+ </AccountsPageContents>
+);
diff --git a/web/apps/albums/src/public-album/components/PublicAlbumSingleFileViewer.tsx b/web/apps/albums/src/public-album/components/PublicAlbumSingleFileViewer.tsx
index 8bf3c29c25..7c549760f6 100644
--- a/web/apps/albums/src/public-album/components/PublicAlbumSingleFileViewer.tsx
+++ b/web/apps/albums/src/public-album/components/PublicAlbumSingleFileViewer.tsx
@@ -22,20 +22,19 @@ import { ActivityIndicator } from "ente-base/components/mui/ActivityIndicator";
import { useBaseContext } from "ente-base/context";
import type { PublicAlbumsCredentials } from "ente-base/http";
import log from "ente-base/log";
+import { LazyNotification } from "@/public-album/components/lazy-ui";
import type { AddSaveGroup } from "@/gallery/components/utils/save-groups";
import { FileViewer } from "@/gallery/components/viewer/FileViewer";
import { createPSRegisterElementIconHTML } from "@/gallery/components/viewer/icons";
import { downloadManager } from "@/gallery/services/download";
-import { downloadAndSaveFiles } from "@/gallery/services/save";
import type { EnteFile } from "ente-media/file";
import { fileFileName } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
-import { Notification } from "ente-new/photos/components/Notification";
import { t } from "i18next";
import { useCallback, useEffect, useMemo, useState } from "react";
import { getEnteURL } from "@/public-album/utils/public-album";
-interface PublicAlbumSingleFileViewerProps {
+export interface PublicAlbumSingleFileViewerProps {
file: EnteFile;
publicAlbumsCredentials: PublicAlbumsCredentials;
collectionKey: string;
@@ -353,12 +352,16 @@ export const PublicAlbumSingleFileViewer: React.FC<
const handleMenuClose = useCallback(() => setMenuAnchorEl(null), []);
const handleDownload = useCallback(
- (targetFile: EnteFile) =>
- downloadAndSaveFiles(
+ async (targetFile: EnteFile) => {
+ const { downloadAndSaveFiles } = await import(
+ "@/gallery/services/save"
+ );
+ return downloadAndSaveFiles(
[targetFile],
fileFileName(targetFile),
onAddSaveGroup,
- ),
+ );
+ },
[onAddSaveGroup],
);
@@ -742,16 +745,18 @@ export const PublicAlbumSingleFileViewer: React.FC<
<ActivityIndicator />
</Box>
)}
- <Notification
- open={showCopiedMessage}
- onClose={() => setShowCopiedMessage(false)}
- horizontal="left"
- attributes={{
- color: "secondary",
- startIcon: <CheckIcon />,
- title: "Copied!",
- }}
- />
+ {showCopiedMessage && (
+ <LazyNotification
+ open={showCopiedMessage}
+ onClose={() => setShowCopiedMessage(false)}
+ horizontal="left"
+ attributes={{
+ color: "secondary",
+ startIcon: <CheckIcon />,
+ title: "Copied!",
+ }}
+ />
+ )}
</>
);
};
diff --git a/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx b/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx
index 2aac5367cf..80c2965b5f 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/MobileNavBar.tsx
@@ -4,10 +4,10 @@ import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import ShareIcon from "@mui/icons-material/Share";
import { Box, Button, IconButton, styled } from "@mui/material";
import { FeedIcon } from "@/public-album/components/Collections/FeedIcon";
+import { LazyNotification } from "@/public-album/components/lazy-ui";
import { EnteLogo } from "ente-base/components/EnteLogo";
import type { PublicAlbumsCredentials } from "ente-base/http";
import type { Collection } from "ente-media/collection";
-import { Notification } from "ente-new/photos/components/Notification";
import { useJoinAlbum } from "@/public-album/hooks/useJoinAlbum";
import { t } from "i18next";
import { useState } from "react";
@@ -126,16 +126,18 @@ export const MobileNavBar: React.FC<MobileNavBarProps> = ({
</ButtonGroup>
</MobileNavContainer>
- <Notification
- open={showCopiedMessage}
- onClose={() => setShowCopiedMessage(false)}
- horizontal="left"
- attributes={{
- color: "secondary",
- startIcon: <CheckIcon />,
- title: "Copied!",
- }}
- />
+ {showCopiedMessage && (
+ <LazyNotification
+ open={showCopiedMessage}
+ onClose={() => setShowCopiedMessage(false)}
+ horizontal="left"
+ attributes={{
+ color: "secondary",
+ startIcon: <CheckIcon />,
+ title: "Copied!",
+ }}
+ />
+ )}
</>
);
};
diff --git a/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx b/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx
index 89212e7e16..85c9c9a61a 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/TopNavButtons.tsx
@@ -4,9 +4,9 @@ import FileDownloadOutlinedIcon from "@mui/icons-material/FileDownloadOutlined";
import ShareIcon from "@mui/icons-material/Share";
import { Box, Button, IconButton, styled } from "@mui/material";
import { FeedIcon } from "@/public-album/components/Collections/FeedIcon";
+import { LazyNotification } from "@/public-album/components/lazy-ui";
import type { PublicAlbumsCredentials } from "ente-base/http";
import type { Collection } from "ente-media/collection";
-import { Notification } from "ente-new/photos/components/Notification";
import { useJoinAlbum } from "@/public-album/hooks/useJoinAlbum";
import { t } from "i18next";
import { useState } from "react";
@@ -91,16 +91,18 @@ export const TopNavButtons: React.FC<TopNavButtonsProps> = ({
</SignUpButton>
</ButtonContainer>
- <Notification
- open={showCopiedMessage}
- onClose={() => setShowCopiedMessage(false)}
- horizontal="left"
- attributes={{
- color: "secondary",
- startIcon: <CheckIcon />,
- title: "Copied!",
- }}
- />
+ {showCopiedMessage && (
+ <LazyNotification
+ open={showCopiedMessage}
+ onClose={() => setShowCopiedMessage(false)}
+ horizontal="left"
+ attributes={{
+ color: "secondary",
+ startIcon: <CheckIcon />,
+ title: "Copied!",
+ }}
+ />
+ )}
</>
);
};
diff --git a/web/apps/albums/src/public-album/components/TripLayout/index.tsx b/web/apps/albums/src/public-album/components/TripLayout/index.tsx
index 6594c00357..d2c203cfdf 100644
--- a/web/apps/albums/src/public-album/components/TripLayout/index.tsx
+++ b/web/apps/albums/src/public-album/components/TripLayout/index.tsx
@@ -4,14 +4,15 @@ import { useModalVisibility } from "ente-base/components/utils/modal";
import type { PublicAlbumsCredentials } from "ente-base/http";
import { useSaveGroupsActions } from "@/gallery/components/utils/save-groups";
import {
- FileViewer,
type FileViewerInitialSidebar,
} from "@/gallery/components/viewer/FileViewer";
import {
- PublicFeedSidebar,
type PublicFeedItemClickInfo,
} from "@/gallery/components/viewer/PublicFeedSidebar";
-import { downloadAndSaveCollectionFiles } from "@/gallery/services/save";
+import {
+ LazyFileViewer,
+ LazyPublicFeedSidebar,
+} from "@/gallery/components/viewer/lazy";
import { type Collection } from "ente-media/collection";
import { type EnteFile } from "ente-media/file";
import { useJoinAlbum } from "@/public-album/hooks/useJoinAlbum";
@@ -39,7 +40,7 @@ import { useThumbnailGeneration } from "./hooks/useThumbnailGeneration";
import type { JourneyPoint } from "./types";
import type { PositionInfo } from "./utils/scrollUtils";
-interface TripLayoutProps {
+export interface TripLayoutProps {
files: EnteFile[];
collection?: Collection;
albumTitle?: string;
@@ -155,12 +156,15 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
// Download all files functionality
const downloadAllFiles = () => {
if (!collection) return;
- void downloadAndSaveCollectionFiles(
- collectionTitle,
- collection.id,
- files,
- undefined,
- onAddSaveGroup,
+ void import("@/gallery/services/save").then(
+ ({ downloadAndSaveCollectionFiles }) =>
+ downloadAndSaveCollectionFiles(
+ collectionTitle,
+ collection.id,
+ files,
+ undefined,
+ onAddSaveGroup,
+ ),
);
};
@@ -577,27 +581,32 @@ export const TripLayout: React.FC<TripLayoutProps> = ({
)}
{/* FileViewer for photo gallery */}
- <FileViewer
- open={openFileViewer}
- onClose={handleCloseFileViewerWithCleanup}
- initialIndex={currentFileIndex}
- initialSidebar={initialSidebar}
- highlightCommentID={highlightCommentID}
- files={viewerFiles}
- disableDownload={!enableDownload}
- publicAlbumsCredentials={credentials?.current}
- collectionKey={collectionKey}
- onJoinAlbum={handleJoinAlbum}
- enableComment={enableComment}
- enableJoin={enableJoin}
- />
+ {openFileViewer && (
+ <LazyFileViewer
+ open={openFileViewer}
+ onClose={handleCloseFileViewerWithCleanup}
+ initialIndex={currentFileIndex}
+ initialSidebar={initialSidebar}
+ highlightCommentID={highlightCommentID}
+ files={viewerFiles}
+ disableDownload={!enableDownload}
+ publicAlbumsCredentials={credentials?.current}
+ collectionKey={collectionKey}
+ onJoinAlbum={handleJoinAlbum}
+ enableComment={enableComment}
+ enableJoin={enableJoin}
+ />
+ )}
{/* Download progress notifications */}
<ActiveDownloadStatusNotifications fullWidthOnMobile />
{/* Public feed sidebar */}
- {collection && credentials?.current && collectionKey && (
- <PublicFeedSidebar
+ {publicFeedVisibilityProps.open &&
+ collection &&
+ credentials?.current &&
+ collectionKey && (
+ <LazyPublicFeedSidebar
{...publicFeedVisibilityProps}
files={files}
credentials={credentials.current}
diff --git a/web/apps/albums/src/public-album/components/Upload.tsx b/web/apps/albums/src/public-album/components/Upload.tsx
index 3d3859366f..6bcf382f64 100644
--- a/web/apps/albums/src/public-album/components/Upload.tsx
+++ b/web/apps/albums/src/public-album/components/Upload.tsx
@@ -70,7 +70,7 @@ interface RemotePullOpts {
silent?: boolean;
}
-interface UploadProps {
+export interface UploadProps {
publicAlbumsCredentials?: PublicAlbumsCredentials;
uploadTypeSelectorView: boolean;
dragAndDropFiles: File[];
@@ -81,6 +81,7 @@ interface UploadProps {
onRemotePull: (opts?: RemotePullOpts) => Promise<void>;
onUploadFile: (file: EnteFile) => void;
onShowSessionExpiredDialog: () => void;
+ onUploadInProgressChange?: (value: boolean) => void;
}
type UploadType = "files" | "folders";
@@ -100,6 +101,7 @@ export const Upload: React.FC<UploadProps> = ({
onRemotePull,
onUploadFile,
onShowSessionExpiredDialog,
+ onUploadInProgressChange,
...props
}) => {
const { onGenericError } = useBaseContext();
@@ -143,6 +145,12 @@ export const Upload: React.FC<UploadProps> = ({
const [isInputPending, setIsInputPending] = useState(false);
const [selectedInputFiles, setSelectedInputFiles] = useState<File[]>([]);
+ const reportUploadInProgress = useCallback(
+ (value: boolean = uploadManager.isUploadInProgress()) =>
+ onUploadInProgressChange?.(value),
+ [onUploadInProgressChange],
+ );
+
const handleInputSelect = useCallback((files: File[]) => {
setIsInputPending(false);
setSelectedInputFiles(files);
@@ -198,7 +206,15 @@ export const Upload: React.FC<UploadProps> = ({
if (uploadManager.isUploadRunning()) {
setUploadProgressView(true);
}
- }, [onUploadFile, publicAlbumsCredentials]);
+ reportUploadInProgress();
+ }, [onUploadFile, publicAlbumsCredentials, reportUploadInProgress]);
+
+ useEffect(
+ () => () => {
+ onUploadInProgressChange?.(false);
+ },
+ [onUploadInProgressChange],
+ );
useEffect(() => {
let files: File[];
@@ -336,6 +352,7 @@ export const Upload: React.FC<UploadProps> = ({
collections: Collection[],
uploaderName?: string,
) => {
+ reportUploadInProgress(true);
try {
await preUploadAction();
const wereFilesProcessed = await uploadManager.uploadItems(
@@ -349,11 +366,13 @@ export const Upload: React.FC<UploadProps> = ({
closeUploadProgress();
notifyUser(e);
} finally {
+ reportUploadInProgress(false);
postUploadAction();
}
};
const retryFailed = async () => {
+ reportUploadInProgress(true);
try {
log.info("Retrying failed uploads");
const { items, collections, parsedMetadataJSONMap } =
@@ -366,6 +385,7 @@ export const Upload: React.FC<UploadProps> = ({
closeUploadProgress();
notifyUser(e);
} finally {
+ reportUploadInProgress(false);
postUploadAction();
}
};
diff --git a/web/apps/albums/src/public-album/components/lazy-ui.ts b/web/apps/albums/src/public-album/components/lazy-ui.ts
new file mode 100644
index 0000000000..46327edae2
--- /dev/null
+++ b/web/apps/albums/src/public-album/components/lazy-ui.ts
@@ -0,0 +1,17 @@
+import dynamic from "next/dynamic";
+
+export const LazyNotification = dynamic(
+ () =>
+ import("ente-new/photos/components/Notification").then(
+ ({ Notification }) => Notification,
+ ),
+ { ssr: false },
+);
+
+export const LazyAttributedMiniDialog = dynamic(
+ () =>
+ import("ente-base/components/MiniDialog").then(
+ ({ AttributedMiniDialog }) => AttributedMiniDialog,
+ ),
+ { ssr: false },
+);
diff --git a/web/apps/albums/src/public-album/hooks/useJoinAlbum.ts b/web/apps/albums/src/public-album/hooks/useJoinAlbum.ts
index 36d9291816..0876a2ce89 100644
--- a/web/apps/albums/src/public-album/hooks/useJoinAlbum.ts
+++ b/web/apps/albums/src/public-album/hooks/useJoinAlbum.ts
@@ -1,6 +1,7 @@
import type { PublicAlbumsCredentials } from "ente-base/http";
-import { albumsAppOrigin, photosAppOrigin } from "ente-base/origins";
import type { Collection } from "ente-media/collection";
+import type { RefObject } from "react";
+import { joinPublicAlbumViaRedirect } from "@/public-album/services/join-public-album-redirect";
export interface UseJoinAlbumProps {
/** Collection to join */
@@ -10,7 +11,7 @@ export interface UseJoinAlbumProps {
/** Collection key from URL (base64 encoded) */
collectionKey?: string;
/** Credentials ref for JWT token access */
- credentials?: React.RefObject<PublicAlbumsCredentials | undefined>;
+ credentials?: RefObject<PublicAlbumsCredentials | undefined>;
}
export interface UseJoinAlbumReturn {
@@ -18,90 +19,6 @@ export interface UseJoinAlbumReturn {
handleJoinAlbum: () => void;
}
-/**
- * Build the web app redirect URL for joining an album.
- */
-const buildWebRedirectURL = (
- accessToken: string,
- collectionId: number,
- currentHash: string,
- jwtToken?: string,
-): string => {
- const webAppURL = photosAppOrigin();
- const hashSuffix = jwtToken ? `&jwt=${encodeURIComponent(jwtToken)}` : "";
- return `${webAppURL}/?joinAlbum=${accessToken}&collectionId=${collectionId}#${currentHash}${hashSuffix}`;
-};
-
-/**
- * Handle the fallback flow when the native app doesn't open.
- * Redirects to web app with all join context in the URL.
- */
-const handleWebFallback = (
- accessToken: string,
- collectionId: number,
- currentHash: string,
- jwtToken?: string,
-): void => {
- // Redirect to web app with joinAlbum parameter
- // The URL contains all necessary context (token, collectionId, JWT, hash) which will be
- // stored on web.ente.io after the domain transition
- const redirectURL = buildWebRedirectURL(
- accessToken,
- collectionId,
- currentHash,
- jwtToken,
- );
- window.location.href = redirectURL;
-};
-
-/**
- * Attempt to open the native app via deep link, with fallback to web.
- * Returns a cleanup function to clear the timeout if needed.
- */
-const tryDeepLinkWithFallback = (
- deepLinkURL: string,
- fallbackFn: () => void | Promise<void>,
- timeoutMs = 2500,
-): (() => void) => {
- let appOpened = false;
-
- // Track visibility changes - app opening will hide the page
- const onVisibilityChange = () => {
- if (document.visibilityState === "hidden") {
- appOpened = true;
- }
- };
-
- // Track page hide - more reliable on some Android browsers
- const onPageHide = () => {
- appOpened = true;
- };
-
- document.addEventListener("visibilitychange", onVisibilityChange);
- window.addEventListener("pagehide", onPageHide);
-
- // Try to open the app using the deep link
- // Use assign() instead of href for better compatibility with iOS Safari/PWAs
- window.location.assign(deepLinkURL);
-
- // Set a timeout to check if the app opened
- const timeoutId = setTimeout(() => {
- if (!appOpened) {
- void fallbackFn();
- }
- cleanup();
- }, timeoutMs);
-
- const cleanup = () => {
- clearTimeout(timeoutId);
- document.removeEventListener("visibilitychange", onVisibilityChange);
- window.removeEventListener("pagehide", onPageHide);
- };
-
- // Return cleanup function
- return cleanup;
-};
-
/**
* Custom hook that provides join album logic and handlers.
* Components can use this hook and apply their own button styling.
@@ -112,35 +29,13 @@ export const useJoinAlbum = ({
collectionKey,
credentials,
}: UseJoinAlbumProps): UseJoinAlbumReturn => {
- const handleJoinAlbum = () => {
- if (!publicCollection || !accessToken || !collectionKey) {
- return;
- }
-
- // Get the original hash directly from the current URL
- const currentHash = window.location.hash.slice(1);
- const jwtToken = credentials?.current?.accessTokenJWT;
- const collectionId = publicCollection.id;
-
- // Create fallback function for mobile deep linking
- const fallbackToWeb = () => {
- handleWebFallback(accessToken, collectionId, currentHash, jwtToken);
- };
-
- // Check if on Android and try deep link with custom scheme with action=join parameter.
- // Skip deep linking on iOS - custom URL schemes show an error
- // dialog when the app isn't installed. On iOS Safari, if the photos app
- // is installed, a banner already appears at the top prompting to open in app.
- if (navigator.userAgent.includes("Android")) {
- const albumsHost = new URL(albumsAppOrigin()).host;
- const deepLinkURL = `ente://${albumsHost}/?action=join&t=${encodeURIComponent(accessToken)}#${currentHash}`;
-
- tryDeepLinkWithFallback(deepLinkURL, fallbackToWeb);
- } else {
- // Desktop and iOS: use the standard web flow directly
- handleWebFallback(accessToken, collectionId, currentHash, jwtToken);
- }
- };
+ const handleJoinAlbum = () =>
+ joinPublicAlbumViaRedirect({
+ publicCollection,
+ accessToken,
+ collectionKey,
+ credentials,
+ });
return { handleJoinAlbum };
};
diff --git a/web/apps/albums/src/public-album/services/join-public-album-redirect.ts b/web/apps/albums/src/public-album/services/join-public-album-redirect.ts
new file mode 100644
index 0000000000..7f0896caa0
--- /dev/null
+++ b/web/apps/albums/src/public-album/services/join-public-album-redirect.ts
@@ -0,0 +1,114 @@
+import type { PublicAlbumsCredentials } from "ente-base/http";
+import { albumsAppOrigin, photosAppOrigin } from "ente-base/origins";
+import type { Collection } from "ente-media/collection";
+import type { RefObject } from "react";
+
+export interface JoinPublicAlbumRedirectProps {
+ publicCollection?: Collection;
+ accessToken?: string;
+ collectionKey?: string;
+ credentials?: RefObject<PublicAlbumsCredentials | undefined>;
+}
+
+/**
+ * Build the web app redirect URL for joining an album.
+ */
+const buildWebRedirectURL = (
+ accessToken: string,
+ collectionId: number,
+ currentHash: string,
+ jwtToken?: string,
+): string => {
+ const webAppURL = photosAppOrigin();
+ const hashSuffix = jwtToken ? `&jwt=${encodeURIComponent(jwtToken)}` : "";
+ return `${webAppURL}/?joinAlbum=${accessToken}&collectionId=${collectionId}#${currentHash}${hashSuffix}`;
+};
+
+/**
+ * Handle the fallback flow when the native app doesn't open.
+ * Redirects to web app with all join context in the URL.
+ */
+const handleWebFallback = (
+ accessToken: string,
+ collectionId: number,
+ currentHash: string,
+ jwtToken?: string,
+): void => {
+ const redirectURL = buildWebRedirectURL(
+ accessToken,
+ collectionId,
+ currentHash,
+ jwtToken,
+ );
+ window.location.href = redirectURL;
+};
+
+/**
+ * Attempt to open the native app via deep link, with fallback to web.
+ * Returns a cleanup function to clear the timeout if needed.
+ */
+const tryDeepLinkWithFallback = (
+ deepLinkURL: string,
+ fallbackFn: () => void | Promise<void>,
+ timeoutMs = 2500,
+): (() => void) => {
+ let appOpened = false;
+
+ const onVisibilityChange = () => {
+ if (document.visibilityState === "hidden") {
+ appOpened = true;
+ }
+ };
+
+ const onPageHide = () => {
+ appOpened = true;
+ };
+
+ document.addEventListener("visibilitychange", onVisibilityChange);
+ window.addEventListener("pagehide", onPageHide);
+
+ window.location.assign(deepLinkURL);
+
+ const timeoutId = setTimeout(() => {
+ if (!appOpened) {
+ void fallbackFn();
+ }
+ cleanup();
+ }, timeoutMs);
+
+ const cleanup = () => {
+ clearTimeout(timeoutId);
+ document.removeEventListener("visibilitychange", onVisibilityChange);
+ window.removeEventListener("pagehide", onPageHide);
+ };
+
+ return cleanup;
+};
+
+export const joinPublicAlbumViaRedirect = ({
+ publicCollection,
+ accessToken,
+ collectionKey,
+ credentials,
+}: JoinPublicAlbumRedirectProps) => {
+ if (!publicCollection || !accessToken || !collectionKey) {
+ return;
+ }
+
+ const currentHash = window.location.hash.slice(1);
+ const jwtToken = credentials?.current?.accessTokenJWT;
+ const collectionId = publicCollection.id;
+
+ const fallbackToWeb = () => {
+ handleWebFallback(accessToken, collectionId, currentHash, jwtToken);
+ };
+
+ if (navigator.userAgent.includes("Android")) {
+ const albumsHost = new URL(albumsAppOrigin()).host;
+ const deepLinkURL = `ente://${albumsHost}/?action=join&t=${encodeURIComponent(accessToken)}#${currentHash}`;
+
+ tryDeepLinkWithFallback(deepLinkURL, fallbackToWeb);
+ } else {
+ handleWebFallback(accessToken, collectionId, currentHash, jwtToken);
+ }
+};
diff --git a/web/apps/albums/src/public-album/services/verify-public-album-password.ts b/web/apps/albums/src/public-album/services/verify-public-album-password.ts
new file mode 100644
index 0000000000..13fda6f0ab
--- /dev/null
+++ b/web/apps/albums/src/public-album/services/verify-public-album-password.ts
@@ -0,0 +1,37 @@
+import { deriveKey } from "ente-base/crypto";
+import {
+ authenticatedPublicAlbumsRequestHeaders,
+ ensureOk,
+} from "ente-base/http";
+import { apiURL } from "ente-base/origins";
+import type { PublicURL } from "ente-media/collection";
+import { z } from "zod";
+
+/**
+ * Verify the password entered for a password-protected public album and return
+ * the JWT token needed for subsequent authenticated public-album requests.
+ */
+export const verifyPublicAlbumPassword = async (
+ publicURL: PublicURL,
+ password: string,
+ accessToken: string,
+) => {
+ const passwordHash = await deriveKey(
+ password,
+ // TODO: Fix the types to not require the bang.
+ publicURL.nonce!,
+ publicURL.opsLimit!,
+ publicURL.memLimit!,
+ );
+
+ const res = await fetch(
+ await apiURL("/public-collection/verify-password"),
+ {
+ method: "POST",
+ headers: authenticatedPublicAlbumsRequestHeaders({ accessToken }),
+ body: JSON.stringify({ passHash: passwordHash }),
+ },
+ );
+ ensureOk(res);
+ return z.object({ jwtToken: z.string() }).parse(await res.json()).jwtToken;
+};