seperate collection summary type from collection type and add new archived collection summary type

This commit is contained in:
Abhinav 2022-06-28 15:13:45 +05:30
parent 4c2bca8e58
commit 96c122f64e
4 changed files with 40 additions and 37 deletions

View file

@ -6,12 +6,18 @@ export enum CollectionType {
folder = 'folder', folder = 'folder',
favorites = 'favorites', favorites = 'favorites',
album = 'album', album = 'album',
}
export enum CollectionSummaryType {
folder = 'folder',
favorites = 'favorites',
album = 'album',
archive = 'archive', archive = 'archive',
trash = 'trash', trash = 'trash',
all = 'all', all = 'all',
shared = 'shared', shared = 'shared',
archived = 'archived',
} }
export enum COLLECTION_SORT_BY { export enum COLLECTION_SORT_BY {
NAME, NAME,
CREATION_TIME_ASCENDING, CREATION_TIME_ASCENDING,
@ -24,34 +30,34 @@ export const COLLECTION_SHARE_DEFAULT_VALID_DURATION =
export const COLLECTION_SHARE_DEFAULT_DEVICE_LIMIT = 4; export const COLLECTION_SHARE_DEFAULT_DEVICE_LIMIT = 4;
export const COLLECTION_SORT_ORDER = new Map([ export const COLLECTION_SORT_ORDER = new Map([
[CollectionType.all, 0], [CollectionSummaryType.all, 0],
[CollectionType.favorites, 1], [CollectionSummaryType.favorites, 1],
[CollectionType.album, 2], [CollectionSummaryType.album, 2],
[CollectionType.folder, 2], [CollectionSummaryType.folder, 2],
[CollectionType.shared, 2], [CollectionSummaryType.shared, 2],
[CollectionType.archive, 3], [CollectionSummaryType.archive, 3],
[CollectionType.trash, 4], [CollectionSummaryType.trash, 4],
]); ]);
export const SYSTEM_COLLECTION_TYPES = new Set([ export const SYSTEM_COLLECTION_TYPES = new Set([
CollectionType.all, CollectionSummaryType.all,
CollectionType.archive, CollectionSummaryType.archive,
CollectionType.trash, CollectionSummaryType.trash,
]); ]);
export const UPLOAD_ALLOWED_COLLECTION_TYPES = new Set([ export const UPLOAD_ALLOWED_COLLECTION_TYPES = new Set([
CollectionType.album, CollectionSummaryType.album,
CollectionType.folder, CollectionSummaryType.folder,
CollectionType.favorites, CollectionSummaryType.favorites,
]); ]);
export const OPTIONS_HAVING_COLLECTION_TYPES = new Set([ export const OPTIONS_HAVING_COLLECTION_TYPES = new Set([
CollectionType.folder, CollectionSummaryType.folder,
CollectionType.album, CollectionSummaryType.album,
CollectionType.trash, CollectionSummaryType.trash,
]); ]);
export const HIDE_FROM_COLLECTION_BAR_TYPES = new Set([ export const HIDE_FROM_COLLECTION_BAR_TYPES = new Set([
CollectionType.trash, CollectionSummaryType.trash,
CollectionType.archive, CollectionSummaryType.archive,
]); ]);

View file

@ -32,6 +32,7 @@ import {
TRASH_SECTION, TRASH_SECTION,
COLLECTION_SORT_ORDER, COLLECTION_SORT_ORDER,
ALL_SECTION, ALL_SECTION,
CollectionSummaryType,
} from 'constants/collection'; } from 'constants/collection';
import { UpdateMagicMetadataRequest } from 'types/magicMetadata'; import { UpdateMagicMetadataRequest } from 'types/magicMetadata';
import { EncryptionResult } from 'types/upload'; import { EncryptionResult } from 'types/upload';
@ -786,8 +787,10 @@ export function getCollectionSummaries(
updationTime: collection.updationTime, updationTime: collection.updationTime,
type: type:
collection.owner.id !== user.id collection.owner.id !== user.id
? CollectionType.shared ? CollectionSummaryType.shared
: collection.type, : IsArchived(collection)
? CollectionSummaryType.archived
: CollectionSummaryType[collection.type],
}); });
} }
} }
@ -853,7 +856,7 @@ function getAllCollectionSummaries(
return { return {
id: ALL_SECTION, id: ALL_SECTION,
name: constants.ALL_SECTION_NAME, name: constants.ALL_SECTION_NAME,
type: CollectionType.all, type: CollectionSummaryType.all,
latestFile: collectionsLatestFile.get(ALL_SECTION), latestFile: collectionsLatestFile.get(ALL_SECTION),
fileCount: allSectionFileCount, fileCount: allSectionFileCount,
updationTime: collectionsLatestFile.get(ALL_SECTION)?.updationTime, updationTime: collectionsLatestFile.get(ALL_SECTION)?.updationTime,
@ -867,7 +870,7 @@ function getArchivedCollectionSummaries(
return { return {
id: ARCHIVE_SECTION, id: ARCHIVE_SECTION,
name: constants.ARCHIVE_SECTION_NAME, name: constants.ARCHIVE_SECTION_NAME,
type: CollectionType.archive, type: CollectionSummaryType.archive,
latestFile: collectionsLatestFile.get(ARCHIVE_SECTION), latestFile: collectionsLatestFile.get(ARCHIVE_SECTION),
fileCount: collectionFilesCount.get(ARCHIVE_SECTION) ?? 0, fileCount: collectionFilesCount.get(ARCHIVE_SECTION) ?? 0,
updationTime: collectionsLatestFile.get(ARCHIVE_SECTION)?.updationTime, updationTime: collectionsLatestFile.get(ARCHIVE_SECTION)?.updationTime,
@ -881,7 +884,7 @@ function getTrashedCollectionSummaries(
return { return {
id: TRASH_SECTION, id: TRASH_SECTION,
name: constants.TRASH, name: constants.TRASH,
type: CollectionType.trash, type: CollectionSummaryType.trash,
latestFile: collectionsLatestFile.get(TRASH_SECTION), latestFile: collectionsLatestFile.get(TRASH_SECTION),
fileCount: collectionFilesCount.get(TRASH_SECTION) ?? 0, fileCount: collectionFilesCount.get(TRASH_SECTION) ?? 0,
updationTime: collectionsLatestFile.get(TRASH_SECTION)?.updationTime, updationTime: collectionsLatestFile.get(TRASH_SECTION)?.updationTime,

View file

@ -1,6 +1,6 @@
import { User } from 'types/user'; import { User } from 'types/user';
import { EnteFile } from 'types/file'; import { EnteFile } from 'types/file';
import { CollectionType } from 'constants/collection'; import { CollectionSummaryType, CollectionType } from 'constants/collection';
import { MagicMetadataCore, VISIBILITY_STATE } from 'types/magicMetadata'; import { MagicMetadataCore, VISIBILITY_STATE } from 'types/magicMetadata';
export interface Collection { export interface Collection {
@ -91,7 +91,7 @@ export interface CollectionMagicMetadata
export interface CollectionSummary { export interface CollectionSummary {
id: number; id: number;
name: string; name: string;
type: CollectionType; type: CollectionSummaryType;
latestFile: EnteFile; latestFile: EnteFile;
fileCount: number; fileCount: number;
updationTime: number; updationTime: number;
@ -99,10 +99,3 @@ export interface CollectionSummary {
export type CollectionSummaries = Map<number, CollectionSummary>; export type CollectionSummaries = Map<number, CollectionSummary>;
export type CollectionFilesCount = Map<number, number>; export type CollectionFilesCount = Map<number, number>;
export interface CollectionInfo {
id: number;
name: string;
fileCount: number;
type: CollectionType;
}

View file

@ -20,6 +20,7 @@ import {
CollectionSummaries, CollectionSummaries,
} from 'types/collection'; } from 'types/collection';
import { import {
CollectionSummaryType,
CollectionType, CollectionType,
HIDE_FROM_COLLECTION_BAR_TYPES, HIDE_FROM_COLLECTION_BAR_TYPES,
OPTIONS_HAVING_COLLECTION_TYPES, OPTIONS_HAVING_COLLECTION_TYPES,
@ -208,18 +209,18 @@ export const hasNonEmptyCollections = (
return collectionSummaries?.size <= 3; return collectionSummaries?.size <= 3;
}; };
export const isUploadAllowedCollection = (type: CollectionType) => { export const isUploadAllowedCollection = (type: CollectionSummaryType) => {
return UPLOAD_ALLOWED_COLLECTION_TYPES.has(type); return UPLOAD_ALLOWED_COLLECTION_TYPES.has(type);
}; };
export const isSystemCollection = (type: CollectionType) => { export const isSystemCollection = (type: CollectionSummaryType) => {
return SYSTEM_COLLECTION_TYPES.has(type); return SYSTEM_COLLECTION_TYPES.has(type);
}; };
export const isOptionsHavingCollection = (type: CollectionType) => { export const isOptionsHavingCollection = (type: CollectionSummaryType) => {
return OPTIONS_HAVING_COLLECTION_TYPES.has(type); return OPTIONS_HAVING_COLLECTION_TYPES.has(type);
}; };
export const shouldBeShownOnCollectionBar = (type: CollectionType) => { export const shouldBeShownOnCollectionBar = (type: CollectionSummaryType) => {
return !HIDE_FROM_COLLECTION_BAR_TYPES.has(type); return !HIDE_FROM_COLLECTION_BAR_TYPES.has(type);
}; };