update collection summary
This commit is contained in:
parent
5652811918
commit
f66eaa8c71
|
@ -1,12 +1,6 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useMemo } from 'react';
|
||||||
import AddCollectionButton from './AddCollectionButton';
|
import AddCollectionButton from './AddCollectionButton';
|
||||||
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
import { Collection, CollectionSummaries } from 'types/collection';
|
||||||
import { User } from 'types/user';
|
|
||||||
import {
|
|
||||||
Collection,
|
|
||||||
CollectionSummaries,
|
|
||||||
CollectionSummary,
|
|
||||||
} from 'types/collection';
|
|
||||||
import { CollectionType } from 'constants/collection';
|
import { CollectionType } from 'constants/collection';
|
||||||
import DialogBoxBase from 'components/DialogBox/base';
|
import DialogBoxBase from 'components/DialogBox/base';
|
||||||
import DialogTitleWithCloseButton from 'components/DialogBox/titleWithCloseButton';
|
import DialogTitleWithCloseButton from 'components/DialogBox/titleWithCloseButton';
|
||||||
|
@ -38,30 +32,28 @@ function CollectionSelector({
|
||||||
collections,
|
collections,
|
||||||
...props
|
...props
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const [collectionToShow, setCollectionToShow] = useState<
|
const collectionToShow = useMemo(() => {
|
||||||
CollectionSummary[]
|
const personalCollectionsOtherThanFrom = [
|
||||||
>([]);
|
...collectionSummaries.values(),
|
||||||
|
]?.filter(
|
||||||
|
({ type, id, isSharedAlbum }) =>
|
||||||
|
id !== attributes.fromCollection &&
|
||||||
|
!isSharedAlbum &&
|
||||||
|
type !== CollectionType.favorites &&
|
||||||
|
type !== CollectionType.system
|
||||||
|
);
|
||||||
|
return personalCollectionsOtherThanFrom;
|
||||||
|
}, [collectionSummaries]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!attributes || !props.open) {
|
if (!attributes || !props.open) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const user: User = getData(LS_KEYS.USER);
|
if (collectionToShow.length === 0) {
|
||||||
const personalCollectionsOtherThanFrom = [
|
|
||||||
...collectionSummaries.values(),
|
|
||||||
]?.filter(
|
|
||||||
({ type, id, attributes: collectionAttributes }) =>
|
|
||||||
id !== attributes.fromCollection &&
|
|
||||||
collectionAttributes.ownerID === user?.id &&
|
|
||||||
type !== CollectionType.favorites &&
|
|
||||||
type !== CollectionType.system
|
|
||||||
);
|
|
||||||
if (personalCollectionsOtherThanFrom.length === 0) {
|
|
||||||
props.onClose();
|
props.onClose();
|
||||||
attributes.showNextModal();
|
attributes.showNextModal();
|
||||||
} else {
|
|
||||||
setCollectionToShow(personalCollectionsOtherThanFrom);
|
|
||||||
}
|
}
|
||||||
}, [props.open]);
|
}, [collectionToShow, attributes, props.open]);
|
||||||
|
|
||||||
if (!attributes) {
|
if (!attributes) {
|
||||||
return <></>;
|
return <></>;
|
||||||
|
|
|
@ -35,6 +35,7 @@ import { UpdateMagicMetadataRequest } from 'types/magicMetadata';
|
||||||
import { EncryptionResult } from 'types/upload';
|
import { EncryptionResult } from 'types/upload';
|
||||||
import constants from 'utils/strings/constants';
|
import constants from 'utils/strings/constants';
|
||||||
import { IsArchived } from 'utils/magicMetadata';
|
import { IsArchived } from 'utils/magicMetadata';
|
||||||
|
import { User } from 'types/user';
|
||||||
|
|
||||||
const ENDPOINT = getEndpoint();
|
const ENDPOINT = getEndpoint();
|
||||||
const COLLECTION_TABLE = 'collections';
|
const COLLECTION_TABLE = 'collections';
|
||||||
|
@ -727,9 +728,7 @@ export function sortCollectionSummaries(
|
||||||
compareCollectionsLatestFile(b.latestFile, a.latestFile)
|
compareCollectionsLatestFile(b.latestFile, a.latestFile)
|
||||||
);
|
);
|
||||||
case COLLECTION_SORT_BY.UPDATION_TIME_DESCENDING:
|
case COLLECTION_SORT_BY.UPDATION_TIME_DESCENDING:
|
||||||
return (
|
return b.updationTime - a.updationTime;
|
||||||
b.attributes.updationTime - a.attributes.updationTime
|
|
||||||
);
|
|
||||||
case COLLECTION_SORT_BY.NAME:
|
case COLLECTION_SORT_BY.NAME:
|
||||||
return a.name.localeCompare(b.name);
|
return a.name.localeCompare(b.name);
|
||||||
}
|
}
|
||||||
|
@ -763,6 +762,7 @@ export function getCollectionSummaries(
|
||||||
const collectionSummaries: CollectionSummaries = new Map();
|
const collectionSummaries: CollectionSummaries = new Map();
|
||||||
const collectionLatestFiles = getCollectionLatestFiles(files);
|
const collectionLatestFiles = getCollectionLatestFiles(files);
|
||||||
const collectionFilesCount = getCollectionsFileCount(files);
|
const collectionFilesCount = getCollectionsFileCount(files);
|
||||||
|
const user: User = getData(LS_KEYS.USER);
|
||||||
|
|
||||||
for (const collection of collections) {
|
for (const collection of collections) {
|
||||||
collectionSummaries.set(collection.id, {
|
collectionSummaries.set(collection.id, {
|
||||||
|
@ -771,10 +771,8 @@ export function getCollectionSummaries(
|
||||||
type: collection.type,
|
type: collection.type,
|
||||||
latestFile: collectionLatestFiles.get(collection.id),
|
latestFile: collectionLatestFiles.get(collection.id),
|
||||||
fileCount: collectionFilesCount.get(collection.id) ?? 0,
|
fileCount: collectionFilesCount.get(collection.id) ?? 0,
|
||||||
attributes: {
|
updationTime: collection.updationTime,
|
||||||
updationTime: collection.updationTime,
|
isSharedAlbum: collection.owner.id !== user.id,
|
||||||
ownerID: collection.owner.id,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
collectionSummaries.set(
|
collectionSummaries.set(
|
||||||
|
@ -806,14 +804,16 @@ function getCollectionsFileCount(files: EnteFile[]): CollectionFilesCount {
|
||||||
function getArchivedCollectionSummaries(
|
function getArchivedCollectionSummaries(
|
||||||
collectionFilesCount: CollectionFilesCount,
|
collectionFilesCount: CollectionFilesCount,
|
||||||
collectionsLatestFile: CollectionLatestFiles
|
collectionsLatestFile: CollectionLatestFiles
|
||||||
) {
|
): CollectionSummary {
|
||||||
return {
|
return {
|
||||||
id: TRASH_SECTION,
|
id: ARCHIVE_SECTION,
|
||||||
name: constants.ARCHIVE,
|
name: constants.ARCHIVE,
|
||||||
type: CollectionType.system,
|
type: CollectionType.system,
|
||||||
latestFile: collectionsLatestFile.get(ARCHIVE_SECTION),
|
latestFile: collectionsLatestFile.get(ARCHIVE_SECTION),
|
||||||
fileCount: collectionFilesCount.get(ARCHIVE_SECTION) ?? 0,
|
fileCount: collectionFilesCount.get(ARCHIVE_SECTION) ?? 0,
|
||||||
} as CollectionSummary;
|
updationTime: collectionsLatestFile.get(ARCHIVE_SECTION)?.updationTime,
|
||||||
|
isSharedAlbum: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTrashedCollectionSummaries(
|
function getTrashedCollectionSummaries(
|
||||||
|
@ -826,5 +826,7 @@ function getTrashedCollectionSummaries(
|
||||||
type: CollectionType.system,
|
type: CollectionType.system,
|
||||||
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,
|
||||||
|
isSharedAlbum: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,12 +92,10 @@ export interface CollectionSummary {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
type: CollectionType;
|
type: CollectionType;
|
||||||
latestFile?: EnteFile;
|
latestFile: EnteFile;
|
||||||
fileCount: number;
|
fileCount: number;
|
||||||
attributes?: {
|
updationTime: number;
|
||||||
ownerID?: number;
|
isSharedAlbum: boolean;
|
||||||
updationTime?: number;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CollectionSummaries = Map<number, CollectionSummary>;
|
export type CollectionSummaries = Map<number, CollectionSummary>;
|
||||||
|
|
Loading…
Reference in a new issue