From be4536ac30c4b84cdef309a9cc4e950298b4a231 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 24 Sep 2024 14:26:49 +0530 Subject: [PATCH] extract --- web/apps/photos/src/pages/shared-albums.tsx | 108 +++++++++++--------- 1 file changed, 62 insertions(+), 46 deletions(-) diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsx index 5d54327925..5680a796bb 100644 --- a/web/apps/photos/src/pages/shared-albums.tsx +++ b/web/apps/photos/src/pages/shared-albums.tsx @@ -275,58 +275,21 @@ export default function PublicCollectionGallery() { main(); }, []); - const downloadEnabled = useMemo( - () => publicCollection?.publicURLs?.[0]?.enableDownload ?? true, - [publicCollection], - ); - - const downloadAllFiles = async () => { - try { - if (!downloadEnabled) { - return; - } - const setFilesDownloadProgressAttributes = - setFilesDownloadProgressAttributesCreator( - publicCollection.name, - publicCollection.id, - isHiddenCollection(publicCollection), - ); - await downloadCollectionFiles( - publicCollection.name, - publicFiles, - setFilesDownloadProgressAttributes, - ); - } catch (e) { - log.error("failed to downloads shared album all files", e); - } - }; + const downloadEnabled = + publicCollection?.publicURLs?.[0]?.enableDownload ?? true; useEffect(() => { publicCollection && publicFiles && setPhotoListHeader({ item: ( - - - - {downloadEnabled && ( - } - > - } - onClick={downloadAllFiles} - > - {t("download_album")} - - - )} - - + ), itemType: ITEM_TYPE.HEADER, height: 68, @@ -733,3 +696,56 @@ const SelectedFileOptions: React.FC = ({ ); }; + +interface ListHeaderProps { + publicCollection: Collection; + publicFiles: EnteFile[]; + setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator; +} + +const ListHeader: React.FC = ({ + publicCollection, + publicFiles, + setFilesDownloadProgressAttributesCreator, +}) => { + const downloadEnabled = + publicCollection.publicURLs?.[0]?.enableDownload ?? true; + + const downloadAllFiles = async () => { + const setFilesDownloadProgressAttributes = + setFilesDownloadProgressAttributesCreator( + publicCollection.name, + publicCollection.id, + isHiddenCollection(publicCollection), + ); + await downloadCollectionFiles( + publicCollection.name, + publicFiles, + setFilesDownloadProgressAttributes, + ); + }; + + return ( + + + + {downloadEnabled && ( + } + > + } + onClick={downloadAllFiles} + > + {t("download_album")} + + + )} + + + ); +};