Skip to content

armgit / ente

Public Imported from GitHub
0

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

Sketch 3

Manav Rathidcb4dd494439
diff --git a/web/apps/photos/src/components/DownloadStatusNotifications.tsx b/web/apps/photos/src/components/DownloadStatusNotifications.tsx
index f83035bdcd..a48afc16cd 100644
--- a/web/apps/photos/src/components/DownloadStatusNotifications.tsx
+++ b/web/apps/photos/src/components/DownloadStatusNotifications.tsx
@@ -4,7 +4,7 @@ import {
isSaveCompleteWithErrors,
isSaveStarted,
type SaveGroup,
-} from "ente-gallery/services/save";
+} from "ente-gallery/components/utils/save-groups";
import { Notification } from "ente-new/photos/components/Notification";
import { t } from "i18next";
@@ -21,7 +21,7 @@ interface DownloadStatusNotificationsProps {
* Called when the user closes the download status associated with the given
* {@link saveGroup}.
*/
- onCloseSaveGroup: (saveGroup: SaveGroup) => void;
+ onRemoveSaveGroup: (saveGroup: SaveGroup) => void;
/**
* Called when the hidden section should be shown.
*
@@ -51,7 +51,7 @@ export const DownloadStatusNotifications: React.FC<
DownloadStatusNotificationsProps
> = ({
saveGroups,
- onCloseSaveGroup,
+ onRemoveSaveGroup,
onShowHiddenSection,
onShowCollection,
}) => {
@@ -66,7 +66,7 @@ export const DownloadStatusNotifications: React.FC<
color: "critical",
action: () => {
group?.canceller.abort();
- onCloseSaveGroup(group);
+ onRemoveSaveGroup(group);
},
},
cancel: t("no"),
@@ -74,7 +74,7 @@ export const DownloadStatusNotifications: React.FC<
const createOnClose = (group: SaveGroup) => () => {
if (isSaveComplete(group)) {
- onCloseSaveGroup(group);
+ onRemoveSaveGroup(group);
} else {
confirmCancelDownload(group);
}
@@ -125,9 +125,9 @@ export const DownloadStatusNotifications: React.FC<
? t("download_failed")
: isSaveComplete(group)
? t("download_complete")
- : t("downloading_album", { name: group.folderName }),
+ : t("downloading_album", { name: group.title }),
caption: isSaveComplete(group)
- ? group.folderName
+ ? group.title
: t("download_progress", {
count: group.success + group.failed,
total: group.total,
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 738508e5bc..52ae6589e1 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -4,10 +4,7 @@ import MenuIcon from "@mui/icons-material/Menu";
import { IconButton, Stack, Typography } from "@mui/material";
import { AuthenticateUser } from "components/AuthenticateUser";
import { GalleryBarAndListHeader } from "components/Collections/GalleryBarAndListHeader";
-import {
- DownloadStatusNotifications,
- type FilesDownloadProgressAttributes,
-} from "components/DownloadStatusNotifications";
+import { DownloadStatusNotifications } from "components/DownloadStatusNotifications";
import { type TimeStampListItem } from "components/FileList";
import { FileListWithViewer } from "components/FileListWithViewer";
import { FixCreationTime } from "components/FixCreationTime";
@@ -41,11 +38,7 @@ import {
import { savedAuthToken } from "ente-base/token";
import { FullScreenDropZone } from "ente-gallery/components/FullScreenDropZone";
import { type UploadTypeSelectorIntent } from "ente-gallery/components/Upload";
-import type {
- SaveGroup,
- SetFilesDownloadProgressAttributes,
- SetFilesDownloadProgressAttributesCreator,
-} from "ente-gallery/services/save";
+import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
import { type Collection } from "ente-media/collection";
import { type EnteFile } from "ente-media/file";
import { type ItemVisibility } from "ente-media/file-metadata";
@@ -192,10 +185,7 @@ const Page: React.FC = () => {
const [photoListHeader, setPhotoListHeader] =
useState<TimeStampListItem>(null);
- const [
- filesDownloadProgressAttributesList,
- setFilesDownloadProgressAttributesList,
- ] = useState<FilesDownloadProgressAttributes[]>([]);
+ const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
const [, setPostCreateAlbumOp] = useState<CollectionOp | undefined>(
undefined,
);
@@ -632,43 +622,6 @@ const Page: React.FC = () => {
};
};
- const handleCloseSaveGroup = useCallback(({id}) => setFilesDownloadProgressAttributesList((groups) => groups.filter((g) => g.id != id)), []);
-
-
-
- const setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator =
- useCallback((folderName, collectionID, isHidden) => {
- const id = Math.random();
- const updater: SetFilesDownloadProgressAttributes = (value) => {
- setFilesDownloadProgressAttributesList((prev) => {
- const attributes = prev?.find((attr) => attr.id === id);
- const updatedAttributes =
- typeof value == "function"
- ? value(attributes)
- : { ...attributes, ...value };
- const updatedAttributesList = attributes
- ? prev.map((attr) =>
- attr.id === id ? updatedAttributes : attr,
- )
- : [...prev, updatedAttributes];
-
- return updatedAttributesList;
- });
- };
- updater({
- id,
- folderName,
- collectionID,
- isHidden,
- canceller: null,
- total: 0,
- success: 0,
- failed: 0,
- downloadDirPath: null,
- });
- return updater;
- }, []);
-
const handleRemoveFilesFromCollection = (collection: Collection) => {
void (async () => {
showLoadingBar();
@@ -1001,8 +954,7 @@ const Page: React.FC = () => {
}
/>
<DownloadStatusNotifications
- saveGroups={filesDownloadProgressAttributesList}
- onCloseSaveGroup={handleCloseSaveGroup}
+ {...{ saveGroups, onRemoveSaveGroup }}
onShowHiddenSection={handleShowHiddenSection}
onShowCollection={handleShowCollection}
/>
diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsx
index 535060e4bb..23124776e2 100644
--- a/web/apps/photos/src/pages/shared-albums.tsx
+++ b/web/apps/photos/src/pages/shared-albums.tsx
@@ -47,12 +47,11 @@ import {
} from "ente-base/http";
import log from "ente-base/log";
import { FullScreenDropZone } from "ente-gallery/components/FullScreenDropZone";
+import { useSaveGroups } from "ente-gallery/components/utils/save-groups";
import { downloadManager } from "ente-gallery/services/download";
import {
downloadCollectionFiles,
downloadSelectedFiles,
- type SaveGroup,
- type SetFilesDownloadProgressAttributes,
type SetFilesDownloadProgressAttributesCreator,
} from "ente-gallery/services/save";
import { extractCollectionKeyFromShareURL } from "ente-gallery/services/share";
@@ -129,52 +128,7 @@ export default function PublicCollectionGallery() {
collectionID: 0,
context: undefined,
});
-
- const [
- filesDownloadProgressAttributesList,
- setFilesDownloadProgressAttributesList,
- ] = useState<SaveGroup[]>([]);
-
- const handleCloseSaveGroup = useCallback(
- ({ id }) =>
- setFilesDownloadProgressAttributesList((groups) =>
- groups.filter((g) => g.id != id),
- ),
- [],
- );
-
- const setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator =
- useCallback((folderName, collectionID, isHidden) => {
- const id = Math.random();
- const updater: SetFilesDownloadProgressAttributes = (value) => {
- setFilesDownloadProgressAttributesList((prev) => {
- const attributes = prev?.find((attr) => attr.id === id);
- const updatedAttributes =
- typeof value == "function"
- ? value(attributes)
- : { ...attributes, ...value };
- const updatedAttributesList = attributes
- ? prev.map((attr) =>
- attr.id === id ? updatedAttributes : attr,
- )
- : [...prev, updatedAttributes];
-
- return updatedAttributesList;
- });
- };
- updater({
- id,
- folderName,
- collectionID,
- isHidden,
- canceller: null,
- total: 0,
- success: 0,
- failed: 0,
- downloadDirPath: null,
- });
- return updater;
- }, []);
+ const { saveGroups, onAddSaveGroup, onRemoveSaveGroup } = useSaveGroups();
const onAddPhotos = useMemo(() => {
return publicCollection?.publicURLs[0]?.enableCollect
@@ -281,11 +235,7 @@ export default function PublicCollectionGallery() {
setPhotoListHeader({
item: (
<ListHeader
- {...{
- publicCollection,
- publicFiles,
- setFilesDownloadProgressAttributesCreator,
- }}
+ {...{ publicCollection, publicFiles, onAddSaveGroup }}
/>
),
tag: "header",
@@ -561,11 +511,9 @@ export default function PublicCollectionGallery() {
selected={selected}
setSelected={setSelected}
activeCollectionID={PseudoCollectionID.all}
- setFilesDownloadProgressAttributesCreator={
- setFilesDownloadProgressAttributesCreator
- }
onRemotePull={publicAlbumsRemotePull}
onVisualFeedback={handleVisualFeedback}
+ onAddSaveGroup={onAddSaveGroup}
/>
{blockingLoad && <TranslucentLoadingOverlay />}
<Upload
@@ -581,8 +529,7 @@ export default function PublicCollectionGallery() {
{...{ dragAndDropFiles }}
/>
<DownloadStatusNotifications
- saveGroups={filesDownloadProgressAttributesList}
- onCloseSaveGroup={handleCloseSaveGroup}
+ {...{ saveGroups, onRemoveSaveGroup }}
/>
</FullScreenDropZone>
</PublicCollectionGalleryContext.Provider>
diff --git a/web/apps/photos/src/utils/file/index.ts b/web/apps/photos/src/utils/file/index.ts
index d21dadf160..c61f569bb1 100644
--- a/web/apps/photos/src/utils/file/index.ts
+++ b/web/apps/photos/src/utils/file/index.ts
@@ -1,4 +1,5 @@
import type { LocalUser } from "ente-accounts/services/user";
+import type { AddSaveGroup } from "ente-gallery/components/utils/save-groups";
import {
type SetFilesDownloadProgressAttributesCreator,
downloadSelectedFiles,
@@ -60,7 +61,7 @@ export const performFileOp = async (
markTempHidden: (files: EnteFile[]) => void,
clearTempHidden: () => void,
fixCreationTime: (files: EnteFile[]) => void,
- setFilesDownloadProgressAttributesCreator: SetFilesDownloadProgressAttributesCreator,
+ onAddSaveGroup: AddSaveGroup,
) => {
switch (op) {
case "download": {