diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index 508a1c149..6fc7e9a13 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -65,6 +65,8 @@ import { PAGES } from 'types'; import { copyOrMoveFromCollection, COLLECTION_OPS_TYPE, + addIsSharedProperty, + isSharedCollection, } from 'utils/collection'; import { logError } from 'utils/sentry'; @@ -172,6 +174,9 @@ export default function Gallery() { useState>(); const [activeCollection, setActiveCollection] = useState(0); + const [isSharedCollectionActive, setIsSharedCollectionActive] = + useState(false); + useEffect(() => { const key = getKey(SESSION_KEYS.ENCRYPTION_KEY); if (!key) { @@ -220,6 +225,13 @@ export default function Gallery() { }`; router.push(href, undefined, { shallow: true }); }, [activeCollection]); + useEffect( + () => + setIsSharedCollectionActive( + isSharedCollection(collections, activeCollection) + ), + [activeCollection] + ); const syncWithRemote = async (force = false, silent = false) => { if (syncInProgress.current && !force) { @@ -269,10 +281,19 @@ export default function Gallery() { } }; - const setDerivativeState = async (collections, files) => { - const nonEmptyCollections = getNonEmptyCollections(collections, files); - const collectionsAndTheirLatestFile = - await getCollectionsAndTheirLatestFile(nonEmptyCollections, files); + const setDerivativeState = async ( + collections: Collection[], + files: File[] + ) => { + const collectionsWithIsSharedInfo = addIsSharedProperty(collections); + const nonEmptyCollections = getNonEmptyCollections( + collectionsWithIsSharedInfo, + files + ); + const collectionsAndTheirLatestFile = getCollectionsAndTheirLatestFile( + nonEmptyCollections, + files + ); const collectionWiseFiles = sortFilesIntoCollections(files); const collectionFilesCount = new Map(); for (const [id, files] of collectionWiseFiles) { @@ -542,6 +563,7 @@ export default function Gallery() { deleted={deleted} setDialogMessage={setDialogMessage} activeCollection={activeCollection} + isSharedCollection={isSharedCollectionActive} /> {selected.count > 0 && selected.collectionID === activeCollection && ( diff --git a/src/services/collectionService.ts b/src/services/collectionService.ts index fd5fdfcb2..9ecb5494b 100644 --- a/src/services/collectionService.ts +++ b/src/services/collectionService.ts @@ -39,6 +39,7 @@ export interface Collection { encryptedKey: string; keyDecryptionNonce: string; isDeleted: boolean; + isSharedCollection?: boolean; } interface EncryptedFileKey { diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index 5a13cadb8..5353b3077 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -9,6 +9,8 @@ import { getSelectedFiles } from 'utils/file'; import { File } from 'services/fileService'; import { CustomError } from 'utils/common/errorUtil'; import { SelectedState } from 'pages/gallery'; +import { User } from 'services/userService'; +import { getData, LS_KEYS } from 'utils/storage/localStorage'; export enum COLLECTION_OPS_TYPE { ADD, @@ -58,3 +60,23 @@ export async function copyOrMoveFromCollection( export function getSelectedCollection(collectionID: number, collections) { return collections.find((collection) => collection.id === collectionID); } + +export function addIsSharedProperty(collections: Collection[]) { + const user: User = getData(LS_KEYS.USER); + for (const collection of collections) { + if (user.id === collection.owner.id) { + collection.isSharedCollection = false; + } else { + collection.isSharedCollection = true; + } + } + return collections; +} + +export function isSharedCollection( + collections: Collection[], + collectionID: number +) { + return !!collections.find((collection) => collection.id === collectionID) + ?.isSharedCollection; +}