remove unneccessary prop
This commit is contained in:
parent
c37f1ad63b
commit
c9e9c0de69
|
@ -37,7 +37,6 @@ interface Props {
|
|||
directlyShowNextModal: boolean;
|
||||
collectionsAndTheirLatestFile: CollectionAndItsLatestFile[];
|
||||
attributes: CollectionSelectorAttributes;
|
||||
syncWithRemote:(force?: boolean, silent?:boolean)=>Promise<void>;
|
||||
}
|
||||
function CollectionSelector({
|
||||
attributes,
|
||||
|
@ -62,12 +61,11 @@ function CollectionSelector({
|
|||
onClick={() => {
|
||||
attributes.callback(item.collection);
|
||||
props.onHide();
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
<CollectionCard>
|
||||
<PreviewCard
|
||||
file={item.file}
|
||||
updateUrl={() => { }}
|
||||
updateUrl={() => {}}
|
||||
forcedEnable
|
||||
/>
|
||||
<Card.Text className="text-center">
|
||||
|
@ -79,10 +77,11 @@ function CollectionSelector({
|
|||
);
|
||||
|
||||
return (
|
||||
<Modal {...props}
|
||||
<Modal
|
||||
{...props}
|
||||
size="xl"
|
||||
centered contentClassName="plan-selector-modal-content"
|
||||
>
|
||||
centered
|
||||
contentClassName="plan-selector-modal-content">
|
||||
<Modal.Header closeButton onHide={() => props.onHide(true)}>
|
||||
<Modal.Title>{attributes.title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
|
@ -91,8 +90,7 @@ function CollectionSelector({
|
|||
display: 'flex',
|
||||
justifyContent: 'space-around',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
}}>
|
||||
<AddCollectionButton showNextModal={attributes.showNextModal} />
|
||||
{CollectionIcons}
|
||||
</Modal.Body>
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
|
||||
import React, {
|
||||
createContext,
|
||||
useContext,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { clearKeys, getKey, SESSION_KEYS } from 'utils/storage/sessionStorage';
|
||||
import {
|
||||
|
@ -98,19 +104,22 @@ export interface SearchStats {
|
|||
type GalleryContextType = {
|
||||
thumbs: Map<number, string>;
|
||||
files: Map<number, string>;
|
||||
}
|
||||
};
|
||||
|
||||
const defaultGalleryContext: GalleryContextType = {
|
||||
thumbs: new Map(),
|
||||
files: new Map(),
|
||||
};
|
||||
|
||||
export const GalleryContext = createContext<GalleryContextType>(defaultGalleryContext);
|
||||
export const GalleryContext = createContext<GalleryContextType>(
|
||||
defaultGalleryContext,
|
||||
);
|
||||
|
||||
export default function Gallery() {
|
||||
const router = useRouter();
|
||||
const [collections, setCollections] = useState<Collection[]>([]);
|
||||
const [collectionsAndTheirLatestFile, setCollectionsAndTheirLatestFile] = useState<CollectionAndItsLatestFile[]>([]);
|
||||
const [collectionsAndTheirLatestFile, setCollectionsAndTheirLatestFile] =
|
||||
useState<CollectionAndItsLatestFile[]>([]);
|
||||
const [files, setFiles] = useState<File[]>(null);
|
||||
const [favItemIds, setFavItemIds] = useState<Set<number>>();
|
||||
const [bannerMessage, setBannerMessage] = useState<string>(null);
|
||||
|
@ -121,9 +130,11 @@ export default function Gallery() {
|
|||
const [dialogView, setDialogView] = useState(false);
|
||||
const [planModalView, setPlanModalView] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [collectionSelectorAttributes, setCollectionSelectorAttributes] = useState<CollectionSelectorAttributes>(null);
|
||||
const [collectionSelectorAttributes, setCollectionSelectorAttributes] =
|
||||
useState<CollectionSelectorAttributes>(null);
|
||||
const [collectionSelectorView, setCollectionSelectorView] = useState(false);
|
||||
const [collectionNamerAttributes, setCollectionNamerAttributes] = useState<CollectionNamerAttributes>(null);
|
||||
const [collectionNamerAttributes, setCollectionNamerAttributes] =
|
||||
useState<CollectionNamerAttributes>(null);
|
||||
const [collectionNamerView, setCollectionNamerView] = useState(false);
|
||||
const [search, setSearch] = useState<Search>({
|
||||
date: null,
|
||||
|
@ -150,7 +161,8 @@ export default function Gallery() {
|
|||
const resync = useRef(false);
|
||||
const [deleted, setDeleted] = useState<number[]>([]);
|
||||
const appContext = useContext(AppContext);
|
||||
const [collectionFilesCount, setCollectionFilesCount] = useState<Map<number, number>>();
|
||||
const [collectionFilesCount, setCollectionFilesCount] =
|
||||
useState<Map<number, number>>();
|
||||
|
||||
useEffect(() => {
|
||||
const key = getKey(SESSION_KEYS.ENCRYPTION_KEY);
|
||||
|
@ -181,22 +193,19 @@ export default function Gallery() {
|
|||
}, []);
|
||||
|
||||
useEffect(() => setDialogView(true), [dialogMessage]);
|
||||
useEffect(
|
||||
() => {
|
||||
if (collectionSelectorAttributes) {
|
||||
setCollectionSelectorView(true);
|
||||
}
|
||||
},
|
||||
[collectionSelectorAttributes],
|
||||
);
|
||||
useEffect(() => {
|
||||
if (collectionSelectorAttributes) {
|
||||
setCollectionSelectorView(true);
|
||||
}
|
||||
}, [collectionSelectorAttributes]);
|
||||
useEffect(() => setCollectionNamerView(true), [collectionNamerAttributes]);
|
||||
|
||||
const syncWithRemote = async (force = false, silent=false) => {
|
||||
const syncWithRemote = async (force = false, silent = false) => {
|
||||
if (syncInProgress.current && !force) {
|
||||
resync.current= true;
|
||||
resync.current = true;
|
||||
return;
|
||||
}
|
||||
syncInProgress.current=true;
|
||||
syncInProgress.current = true;
|
||||
try {
|
||||
checkConnectivity();
|
||||
if (!(await isTokenValid())) {
|
||||
|
@ -219,7 +228,8 @@ export default function Gallery() {
|
|||
text: constants.LOGIN,
|
||||
action: logoutUser,
|
||||
variant: 'success',
|
||||
} });
|
||||
},
|
||||
});
|
||||
break;
|
||||
case CustomError.KEY_MISSING:
|
||||
clearKeys();
|
||||
|
@ -229,22 +239,17 @@ export default function Gallery() {
|
|||
} finally {
|
||||
!silent && loadingBar.current?.complete();
|
||||
}
|
||||
syncInProgress.current=false;
|
||||
syncInProgress.current = false;
|
||||
if (resync.current) {
|
||||
resync.current=false;
|
||||
resync.current = false;
|
||||
syncWithRemote();
|
||||
}
|
||||
};
|
||||
|
||||
const initDerivativeState = async (collections, files) => {
|
||||
const nonEmptyCollections = getNonEmptyCollections(
|
||||
collections,
|
||||
files,
|
||||
);
|
||||
const collectionsAndTheirLatestFile = await getCollectionsAndTheirLatestFile(
|
||||
nonEmptyCollections,
|
||||
files,
|
||||
);
|
||||
const nonEmptyCollections = getNonEmptyCollections(collections, files);
|
||||
const collectionsAndTheirLatestFile =
|
||||
await getCollectionsAndTheirLatestFile(nonEmptyCollections, files);
|
||||
const collectionWiseFiles = sortFilesIntoCollections(files);
|
||||
const collectionFilesCount = new Map<number, number>();
|
||||
for (const [id, files] of collectionWiseFiles) {
|
||||
|
@ -286,22 +291,20 @@ export default function Gallery() {
|
|||
);
|
||||
};
|
||||
|
||||
const showCreateCollectionModal = () => setCollectionNamerAttributes({
|
||||
title: constants.CREATE_COLLECTION,
|
||||
buttonText: constants.CREATE,
|
||||
autoFilledName: '',
|
||||
callback: (collectionName) => addToCollectionHelper(collectionName, null),
|
||||
});
|
||||
const showCreateCollectionModal = () =>
|
||||
setCollectionNamerAttributes({
|
||||
title: constants.CREATE_COLLECTION,
|
||||
buttonText: constants.CREATE,
|
||||
autoFilledName: '',
|
||||
callback: (collectionName) =>
|
||||
addToCollectionHelper(collectionName, null),
|
||||
});
|
||||
|
||||
const deleteFileHelper = async () => {
|
||||
loadingBar.current?.continuousStart();
|
||||
try {
|
||||
const fileIds = getSelectedFileIds(selected);
|
||||
await deleteFiles(
|
||||
fileIds,
|
||||
clearSelection,
|
||||
syncWithRemote,
|
||||
);
|
||||
await deleteFiles(fileIds, clearSelection, syncWithRemote);
|
||||
setDeleted([...deleted, ...fileIds]);
|
||||
} catch (e) {
|
||||
loadingBar.current.complete();
|
||||
|
@ -330,7 +333,6 @@ export default function Gallery() {
|
|||
setSearchStats(null);
|
||||
};
|
||||
|
||||
|
||||
const closeCollectionSelector = (closeBtnClick?: boolean) => {
|
||||
if (closeBtnClick === true) {
|
||||
appContext.resetSharedFiles();
|
||||
|
@ -343,8 +345,10 @@ export default function Gallery() {
|
|||
<FullScreenDropZone
|
||||
getRootProps={getRootProps}
|
||||
getInputProps={getInputProps}
|
||||
showCollectionSelector={setCollectionSelectorView.bind(null, true)}
|
||||
>
|
||||
showCollectionSelector={setCollectionSelectorView.bind(
|
||||
null,
|
||||
true,
|
||||
)}>
|
||||
{loading && (
|
||||
<LoadingOverlay>
|
||||
<EnteSpinner />
|
||||
|
@ -396,21 +400,30 @@ export default function Gallery() {
|
|||
attributes={collectionNamerAttributes}
|
||||
/>
|
||||
<CollectionSelector
|
||||
show={collectionSelectorView && !(collectionsAndTheirLatestFile?.length === 0)}
|
||||
show={
|
||||
collectionSelectorView &&
|
||||
!(collectionsAndTheirLatestFile?.length === 0)
|
||||
}
|
||||
onHide={closeCollectionSelector}
|
||||
collectionsAndTheirLatestFile={collectionsAndTheirLatestFile}
|
||||
collectionsAndTheirLatestFile={
|
||||
collectionsAndTheirLatestFile
|
||||
}
|
||||
directlyShowNextModal={
|
||||
collectionsAndTheirLatestFile?.length === 0
|
||||
}
|
||||
attributes={collectionSelectorAttributes}
|
||||
syncWithRemote={syncWithRemote}
|
||||
/>
|
||||
<Upload
|
||||
syncWithRemote={syncWithRemote}
|
||||
setBannerMessage={setBannerMessage}
|
||||
acceptedFiles={acceptedFiles}
|
||||
showCollectionSelector={setCollectionSelectorView.bind(null, true)}
|
||||
setCollectionSelectorAttributes={setCollectionSelectorAttributes}
|
||||
showCollectionSelector={setCollectionSelectorView.bind(
|
||||
null,
|
||||
true,
|
||||
)}
|
||||
setCollectionSelectorAttributes={
|
||||
setCollectionSelectorAttributes
|
||||
}
|
||||
closeCollectionSelector={setCollectionSelectorView.bind(
|
||||
null,
|
||||
false,
|
||||
|
@ -428,7 +441,10 @@ export default function Gallery() {
|
|||
setLoading={setLoading}
|
||||
showPlanSelectorModal={() => setPlanModalView(true)}
|
||||
/>
|
||||
<UploadButton isFirstFetch={isFirstFetch} openFileUploader={openFileUploader} />
|
||||
<UploadButton
|
||||
isFirstFetch={isFirstFetch}
|
||||
openFileUploader={openFileUploader}
|
||||
/>
|
||||
<PhotoFrame
|
||||
files={files}
|
||||
setFiles={setFiles}
|
||||
|
|
Loading…
Reference in a new issue