From 0931e590a94cb277d76048cbb9a37b08c3e24d15 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 11 Jun 2025 18:00:44 +0530 Subject: [PATCH] Conv --- .../components/Collections/CollectionHeader.tsx | 7 ++++--- .../photos/src/services/collectionService.ts | 16 ---------------- web/packages/new/photos/services/collection.ts | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/web/apps/photos/src/components/Collections/CollectionHeader.tsx b/web/apps/photos/src/components/Collections/CollectionHeader.tsx index 11062597ee..e6330ecc81 100644 --- a/web/apps/photos/src/components/Collections/CollectionHeader.tsx +++ b/web/apps/photos/src/components/Collections/CollectionHeader.tsx @@ -39,6 +39,7 @@ import { ALL_SECTION, HIDDEN_ITEMS_SECTION, isHiddenCollection, + leaveSharedCollection, } from "ente-new/photos/services/collection"; import type { CollectionSummary, @@ -260,7 +261,7 @@ const CollectionOptions: React.FC = ({ changeCollectionVisibility(activeCollection, ItemVisibility.visible), ); - const confirmLeaveSharedAlbum = () => { + const confirmLeaveSharedAlbum = () => showMiniDialog({ title: t("leave_shared_album_title"), message: t("leave_shared_album_message"), @@ -270,10 +271,10 @@ const CollectionOptions: React.FC = ({ action: leaveSharedAlbum, }, }); - }; + const leaveSharedAlbum = wrap(async () => { - await CollectionAPI.leaveSharedAlbum(activeCollection.id); + await leaveSharedCollection(activeCollection.id); setActiveCollectionID(ALL_SECTION); }); diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts index 7209db5cc1..e0e568434f 100644 --- a/web/apps/photos/src/services/collectionService.ts +++ b/web/apps/photos/src/services/collectionService.ts @@ -334,22 +334,6 @@ export const deleteCollection = async ( } }; -export const leaveSharedAlbum = async (collectionID: number) => { - try { - const token = getToken(); - - await HTTPService.post( - await apiURL(`/collections/leave/${collectionID}`), - null, - null, - { "X-Auth-Token": token }, - ); - } catch (e) { - log.error("leave shared album failed ", e); - throw e; - } -}; - export const updateCollectionMagicMetadata = async ( collection: Collection, updatedMagicMetadata: CollectionMagicMetadata, diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.ts index 17bdf640bc..dcbe72b9b0 100644 --- a/web/packages/new/photos/services/collection.ts +++ b/web/packages/new/photos/services/collection.ts @@ -304,7 +304,7 @@ export const shareCollection = async ( /** * Delete the public link for the collection with given {@link collectionID}. * - * Does not modify local state. + * Remote only, does not modify local state. */ export const deleteShareURL = async (collectionID: number) => ensureOk( @@ -313,3 +313,18 @@ export const deleteShareURL = async (collectionID: number) => headers: await authenticatedRequestHeaders(), }), ); + +/** + * Leave a collection which had previously been shared with the user. + * + * Remote only, does not modify local state. + * + * @param collectionID The ID of the shared collection to leave. + */ +export const leaveSharedCollection = async (collectionID: number) => + ensureOk( + await fetch(await apiURL(`/collections/leave/${collectionID}`), { + method: "POST", + headers: await authenticatedRequestHeaders(), + }), + );