make hidden collections and files unsearchable and add better isValidReplacementCollection check

This commit is contained in:
Abhinav 2023-05-11 12:10:26 +05:30
parent 923bc858e4
commit 0b66a6685a
4 changed files with 42 additions and 6 deletions

View file

@ -44,7 +44,7 @@ import PhotoFrame from 'components/PhotoFrame';
import {
changeFilesVisibility,
downloadFiles,
getNonTrashedFiles,
getSearchableFiles,
getSelectedFiles,
mergeMetadata,
sortFiles,
@ -77,6 +77,7 @@ import {
getSelectedCollection,
getArchivedCollections,
hasNonSystemCollections,
getSearchableCollections,
} from 'utils/collection';
import { logError } from 'utils/sentry';
import {
@ -716,8 +717,8 @@ export default function Gallery() {
setIsInSearchMode={setIsInSearchMode}
openUploader={openUploader}
isInSearchMode={isInSearchMode}
collections={collections}
files={getNonTrashedFiles(files)}
collections={getSearchableCollections(collections)}
files={getSearchableFiles(files)}
setActiveCollection={setActiveCollection}
updateSearch={updateSearch}
/>

View file

@ -55,6 +55,7 @@ import {
isSharedOnlyViaLink,
isValidMoveTarget,
isCollectionHidden,
isValidReplacementCollection,
} from 'utils/collection';
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
import { getLocalFiles } from './fileService';
@ -313,8 +314,16 @@ export const createCollection = async (
if (!existingCollections) {
existingCollections = await syncCollections();
}
const user: User = getData(LS_KEYS.USER);
for (const collection of existingCollections) {
if (collection.name === collectionName) {
if (
isValidReplacementCollection(
collection,
user,
collectionName,
type
)
) {
return collection;
}
}

View file

@ -20,6 +20,7 @@ import {
} from 'types/collection';
import {
CollectionSummaryType,
CollectionType,
HIDE_FROM_COLLECTION_BAR_TYPES,
OPTIONS_NOT_HAVING_COLLECTION_TYPES,
SYSTEM_COLLECTION_TYPES,
@ -257,6 +258,21 @@ export function isValidMoveTarget(
);
}
export function isValidReplacementCollection(
collection: Collection,
user: User,
wantedCollectionName: string,
wantedCollectionType: CollectionType
) {
return (
collection.name !== wantedCollectionName &&
collection.type === wantedCollectionType &&
!isCollectionHidden(collection) &&
!isQuickLinkCollection(collection) &&
!isIncomingShare(collection, user)
);
}
export function getCollectionNameMap(
collections: Collection[]
): Map<number, string> {
@ -282,3 +298,9 @@ export function getNonEmptyPersonalCollections(
);
return personalCollections;
}
export function getSearchableCollections(
collections: Collection[]
): Collection[] {
return collections.filter((collection) => !isCollectionHidden(collection));
}

View file

@ -471,9 +471,13 @@ export function getUniqueFiles(files: EnteFile[]) {
}
});
}
export function getNonTrashedFiles(files: EnteFile[]) {
export function getSearchableFiles(files: EnteFile[]) {
return files.filter(
(file) => typeof file.isTrashed === 'undefined' || !file.isTrashed
(file) =>
typeof file.isTrashed === 'undefined' ||
!file.isTrashed ||
typeof file.isHidden === 'undefined' ||
!file.isHidden
);
}