added isShared property to collection and isSharedCollectionActive state
This commit is contained in:
parent
1e45557e34
commit
5fcde0b6e6
|
@ -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<Map<number, number>>();
|
||||
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<number, number>();
|
||||
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 && (
|
||||
|
|
|
@ -39,6 +39,7 @@ export interface Collection {
|
|||
encryptedKey: string;
|
||||
keyDecryptionNonce: string;
|
||||
isDeleted: boolean;
|
||||
isSharedCollection?: boolean;
|
||||
}
|
||||
|
||||
interface EncryptedFileKey {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue