diff --git a/src/components/Collections/CollectionInfoWithOptions.tsx b/src/components/Collections/CollectionInfoWithOptions.tsx index f1f363d64..bb74d6f80 100644 --- a/src/components/Collections/CollectionInfoWithOptions.tsx +++ b/src/components/Collections/CollectionInfoWithOptions.tsx @@ -5,8 +5,7 @@ import CollectionOptions from 'components/Collections/CollectionOptions'; import { SetCollectionNamerAttributes } from 'components/Collections/CollectionNamer'; import { SpaceBetweenFlex } from 'components/Container'; import { CollectionInfoBarWrapper } from './styledComponents'; -import { isSystemCollection } from 'utils/collection'; -import { TRASH_SECTION } from 'constants/collection'; +import { isOptionsHavingCollection } from 'utils/collection'; interface Iprops { activeCollection: Collection; @@ -32,13 +31,13 @@ export default function CollectionInfoWithOptions({ return <>; } - const { name, type, fileCount, id } = collectionSummary; + const { name, type, fileCount } = collectionSummary; return ( - {(!isSystemCollection(type) || id === TRASH_SECTION) && ( + {isOptionsHavingCollection(type) && ( )} diff --git a/src/components/Collections/CollectionListBar/index.tsx b/src/components/Collections/CollectionListBar/index.tsx index 3a3d3d759..d35db9b60 100644 --- a/src/components/Collections/CollectionListBar/index.tsx +++ b/src/components/Collections/CollectionListBar/index.tsx @@ -15,6 +15,7 @@ import useWindowSize from 'hooks/useWindowSize'; import LinkButton from 'components/pages/gallery/LinkButton'; import { SpaceBetweenFlex } from 'components/Container'; import { sortCollectionSummaries } from 'services/collectionService'; +import { shouldBeShownOnCollectionBar } from 'utils/collection'; interface IProps { activeCollection?: number; @@ -34,8 +35,8 @@ export default function CollectionListBar(props: IProps) { const sortedCollectionSummary = useMemo( () => sortCollectionSummaries( - [...collectionSummaries.values()].filter( - (c) => c.fileCount > 0 + [...collectionSummaries.values()].filter((c) => + shouldBeShownOnCollectionBar(c.type) ), COLLECTION_SORT_BY.UPDATION_TIME_DESCENDING ), diff --git a/src/components/Collections/CollectionSelector/index.tsx b/src/components/Collections/CollectionSelector/index.tsx index aae3f83ad..b932a14ec 100644 --- a/src/components/Collections/CollectionSelector/index.tsx +++ b/src/components/Collections/CollectionSelector/index.tsx @@ -1,7 +1,7 @@ import React, { useContext, useEffect, useMemo } from 'react'; import { Collection, CollectionSummaries } from 'types/collection'; import DialogTitleWithCloseButton from 'components/DialogBox/TitleWithCloseButton'; -import { isSystemCollection } from 'utils/collection'; +import { isUploadAllowedCollection } from 'utils/collection'; import { AppContext } from 'pages/_app'; import { AllCollectionDialog } from 'components/Collections/AllCollections/dialog'; import { DialogContent } from '@mui/material'; @@ -35,7 +35,8 @@ function CollectionSelector({ ...collectionSummaries.values(), ]?.filter( ({ type, id }) => - id !== attributes?.fromCollection && !isSystemCollection(type) + id !== attributes?.fromCollection && + !isUploadAllowedCollection(type) ); return personalCollectionsOtherThanFrom; }, [collectionSummaries, attributes]); diff --git a/src/constants/collection/index.ts b/src/constants/collection/index.ts index c7f097dd0..3b95173a1 100644 --- a/src/constants/collection/index.ts +++ b/src/constants/collection/index.ts @@ -37,5 +37,21 @@ export const SYSTEM_COLLECTION_TYPES = new Set([ CollectionType.all, CollectionType.archive, CollectionType.trash, - CollectionType.shared, +]); + +export const UPLOAD_ALLOWED_COLLECTION_TYPES = new Set([ + CollectionType.album, + CollectionType.folder, + CollectionType.favorites, +]); + +export const OPTIONS_HAVING_COLLECTION_TYPES = new Set([ + CollectionType.folder, + CollectionType.album, + CollectionType.trash, +]); + +export const HIDE_FROM_COLLECTION_BAR_TYPES = new Set([ + CollectionType.trash, + CollectionType.archive, ]); diff --git a/src/utils/collection/index.ts b/src/utils/collection/index.ts index 6635a0e7d..05cc7a94a 100644 --- a/src/utils/collection/index.ts +++ b/src/utils/collection/index.ts @@ -19,7 +19,13 @@ import { CollectionMagicMetadataProps, CollectionSummaries, } from 'types/collection'; -import { CollectionType, SYSTEM_COLLECTION_TYPES } from 'constants/collection'; +import { + CollectionType, + HIDE_FROM_COLLECTION_BAR_TYPES, + OPTIONS_HAVING_COLLECTION_TYPES, + SYSTEM_COLLECTION_TYPES, + UPLOAD_ALLOWED_COLLECTION_TYPES, +} from 'constants/collection'; import { getAlbumSiteHost } from 'constants/pages'; import { getUnixTimeInMicroSecondsWithDelta } from 'utils/time'; import { @@ -202,6 +208,18 @@ export const hasNonEmptyCollections = ( return collectionSummaries?.size <= 3; }; +export const isUploadAllowedCollection = (type: CollectionType) => { + return UPLOAD_ALLOWED_COLLECTION_TYPES.has(type); +}; + export const isSystemCollection = (type: CollectionType) => { return SYSTEM_COLLECTION_TYPES.has(type); }; + +export const isOptionsHavingCollection = (type: CollectionType) => { + return OPTIONS_HAVING_COLLECTION_TYPES.has(type); +}; + +export const shouldBeShownOnCollectionBar = (type: CollectionType) => { + return !HIDE_FROM_COLLECTION_BAR_TYPES.has(type); +};