commit
c3f96e3c1d
|
@ -6,18 +6,20 @@ import {
|
||||||
deleteCollection,
|
deleteCollection,
|
||||||
renameCollection,
|
renameCollection,
|
||||||
} from 'services/collectionService';
|
} from 'services/collectionService';
|
||||||
import { getSelectedCollection } from 'utils/collection';
|
import { downloadCollection, getSelectedCollection } from 'utils/collection';
|
||||||
import constants from 'utils/strings/constants';
|
import constants from 'utils/strings/constants';
|
||||||
import { SetCollectionNamerAttributes } from './CollectionNamer';
|
import { SetCollectionNamerAttributes } from './CollectionNamer';
|
||||||
import LinkButton, { ButtonVariant, LinkButtonProps } from './LinkButton';
|
import LinkButton, { ButtonVariant, LinkButtonProps } from './LinkButton';
|
||||||
|
import { sleep } from 'utils/common';
|
||||||
|
|
||||||
interface Props {
|
interface CollectionOptionsProps {
|
||||||
syncWithRemote: () => Promise<void>;
|
syncWithRemote: () => Promise<void>;
|
||||||
setCollectionNamerAttributes: SetCollectionNamerAttributes;
|
setCollectionNamerAttributes: SetCollectionNamerAttributes;
|
||||||
collections: Collection[];
|
collections: Collection[];
|
||||||
selectedCollectionID: number;
|
selectedCollectionID: number;
|
||||||
setDialogMessage: SetDialogMessage;
|
setDialogMessage: SetDialogMessage;
|
||||||
startLoadingBar: () => void;
|
startLoading: () => void;
|
||||||
|
finishLoading: () => void;
|
||||||
showCollectionShareModal: () => void;
|
showCollectionShareModal: () => void;
|
||||||
redirectToAll: () => void;
|
redirectToAll: () => void;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +45,7 @@ export const MenuItem = (props: { children: any }) => (
|
||||||
</ListGroup.Item>
|
</ListGroup.Item>
|
||||||
);
|
);
|
||||||
|
|
||||||
const CollectionOptions = (props: Props) => {
|
const CollectionOptions = (props: CollectionOptionsProps) => {
|
||||||
const collectionRename = async (
|
const collectionRename = async (
|
||||||
selectedCollection: Collection,
|
selectedCollection: Collection,
|
||||||
newName: string
|
newName: string
|
||||||
|
@ -62,7 +64,7 @@ const CollectionOptions = (props: Props) => {
|
||||||
props.collections
|
props.collections
|
||||||
)?.name,
|
)?.name,
|
||||||
callback: (newName) => {
|
callback: (newName) => {
|
||||||
props.startLoadingBar();
|
props.startLoading();
|
||||||
collectionRename(
|
collectionRename(
|
||||||
getSelectedCollection(
|
getSelectedCollection(
|
||||||
props.selectedCollectionID,
|
props.selectedCollectionID,
|
||||||
|
@ -81,7 +83,7 @@ const CollectionOptions = (props: Props) => {
|
||||||
proceed: {
|
proceed: {
|
||||||
text: constants.DELETE_COLLECTION,
|
text: constants.DELETE_COLLECTION,
|
||||||
action: () => {
|
action: () => {
|
||||||
props.startLoadingBar();
|
props.startLoading();
|
||||||
deleteCollection(
|
deleteCollection(
|
||||||
props.selectedCollectionID,
|
props.selectedCollectionID,
|
||||||
props.syncWithRemote,
|
props.syncWithRemote,
|
||||||
|
@ -97,6 +99,32 @@ const CollectionOptions = (props: Props) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const confirmDownloadCollection = () => {
|
||||||
|
props.setDialogMessage({
|
||||||
|
title: constants.CONFIRM_DOWNLOAD_COLLECTION,
|
||||||
|
content: constants.DOWNLOAD_COLLECTION_MESSAGE(),
|
||||||
|
staticBackdrop: true,
|
||||||
|
proceed: {
|
||||||
|
text: constants.DOWNLOAD,
|
||||||
|
action: downloadCollectionHelper,
|
||||||
|
variant: 'success',
|
||||||
|
},
|
||||||
|
close: {
|
||||||
|
text: constants.CANCEL,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const downloadCollectionHelper = async () => {
|
||||||
|
props.startLoading();
|
||||||
|
await downloadCollection(
|
||||||
|
props.selectedCollectionID,
|
||||||
|
props.setDialogMessage
|
||||||
|
);
|
||||||
|
await sleep(1000);
|
||||||
|
props.finishLoading();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover id="collection-options" style={{ borderRadius: '10px' }}>
|
<Popover id="collection-options" style={{ borderRadius: '10px' }}>
|
||||||
<Popover.Content style={{ padding: 0, border: 'none' }}>
|
<Popover.Content style={{ padding: 0, border: 'none' }}>
|
||||||
|
@ -111,6 +139,11 @@ const CollectionOptions = (props: Props) => {
|
||||||
{constants.SHARE}
|
{constants.SHARE}
|
||||||
</MenuLink>
|
</MenuLink>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem>
|
||||||
|
<MenuLink onClick={confirmDownloadCollection}>
|
||||||
|
{constants.DOWNLOAD}
|
||||||
|
</MenuLink>
|
||||||
|
</MenuItem>
|
||||||
<MenuItem>
|
<MenuItem>
|
||||||
<MenuLink
|
<MenuLink
|
||||||
variant={ButtonVariant.danger}
|
variant={ButtonVariant.danger}
|
||||||
|
|
|
@ -35,7 +35,8 @@ interface CollectionProps {
|
||||||
setDialogMessage: SetDialogMessage;
|
setDialogMessage: SetDialogMessage;
|
||||||
syncWithRemote: () => Promise<void>;
|
syncWithRemote: () => Promise<void>;
|
||||||
setCollectionNamerAttributes: SetCollectionNamerAttributes;
|
setCollectionNamerAttributes: SetCollectionNamerAttributes;
|
||||||
startLoadingBar: () => void;
|
startLoading: () => void;
|
||||||
|
finishLoading: () => void;
|
||||||
isInSearchMode: boolean;
|
isInSearchMode: boolean;
|
||||||
collectionFilesCount: Map<number, number>;
|
collectionFilesCount: Map<number, number>;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +170,8 @@ export default function Collections(props: CollectionProps) {
|
||||||
collections: props.collections,
|
collections: props.collections,
|
||||||
selectedCollectionID,
|
selectedCollectionID,
|
||||||
setDialogMessage: props.setDialogMessage,
|
setDialogMessage: props.setDialogMessage,
|
||||||
startLoadingBar: props.startLoadingBar,
|
startLoading: props.startLoading,
|
||||||
|
finishLoading: props.finishLoading,
|
||||||
showCollectionShareModal: setCollectionShareModalView.bind(null, true),
|
showCollectionShareModal: setCollectionShareModalView.bind(null, true),
|
||||||
redirectToAll: setActiveCollection.bind(null, ALL_SECTION),
|
redirectToAll: setActiveCollection.bind(null, ALL_SECTION),
|
||||||
});
|
});
|
||||||
|
|
|
@ -362,12 +362,17 @@ export default function Gallery() {
|
||||||
setSelected({ count: 0, collectionID: 0 });
|
setSelected({ count: 0, collectionID: 0 });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const startLoading = () =>
|
||||||
|
!syncInProgress.current && loadingBar.current?.continuousStart();
|
||||||
|
const finishLoading = () =>
|
||||||
|
!syncInProgress.current && loadingBar.current.complete();
|
||||||
|
|
||||||
if (!files) {
|
if (!files) {
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
const collectionOpsHelper =
|
const collectionOpsHelper =
|
||||||
(ops: COLLECTION_OPS_TYPE) => async (collection: Collection) => {
|
(ops: COLLECTION_OPS_TYPE) => async (collection: Collection) => {
|
||||||
loadingBar.current?.continuousStart();
|
startLoading();
|
||||||
try {
|
try {
|
||||||
await handleCollectionOps(
|
await handleCollectionOps(
|
||||||
ops,
|
ops,
|
||||||
|
@ -388,14 +393,14 @@ export default function Gallery() {
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await syncWithRemote(false, true);
|
await syncWithRemote(false, true);
|
||||||
loadingBar.current.complete();
|
finishLoading();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const changeFilesVisibilityHelper = async (
|
const changeFilesVisibilityHelper = async (
|
||||||
visibility: VISIBILITY_STATE
|
visibility: VISIBILITY_STATE
|
||||||
) => {
|
) => {
|
||||||
loadingBar.current?.continuousStart();
|
startLoading();
|
||||||
try {
|
try {
|
||||||
const updatedFiles = await changeFilesVisibility(
|
const updatedFiles = await changeFilesVisibility(
|
||||||
files,
|
files,
|
||||||
|
@ -424,7 +429,7 @@ export default function Gallery() {
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await syncWithRemote(false, true);
|
await syncWithRemote(false, true);
|
||||||
loadingBar.current.complete();
|
finishLoading();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -458,7 +463,7 @@ export default function Gallery() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteFileHelper = async (permanent?: boolean) => {
|
const deleteFileHelper = async (permanent?: boolean) => {
|
||||||
loadingBar.current?.continuousStart();
|
startLoading();
|
||||||
try {
|
try {
|
||||||
const selectedFiles = getSelectedFiles(selected, files);
|
const selectedFiles = getSelectedFiles(selected, files);
|
||||||
if (permanent) {
|
if (permanent) {
|
||||||
|
@ -489,7 +494,7 @@ export default function Gallery() {
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await syncWithRemote(false, true);
|
await syncWithRemote(false, true);
|
||||||
loadingBar.current.complete();
|
finishLoading();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -519,7 +524,7 @@ export default function Gallery() {
|
||||||
close: { text: constants.CANCEL },
|
close: { text: constants.CANCEL },
|
||||||
});
|
});
|
||||||
const emptyTrashHelper = async () => {
|
const emptyTrashHelper = async () => {
|
||||||
loadingBar.current?.continuousStart();
|
startLoading();
|
||||||
try {
|
try {
|
||||||
await emptyTrash();
|
await emptyTrash();
|
||||||
if (selected.collectionID === TRASH_SECTION) {
|
if (selected.collectionID === TRASH_SECTION) {
|
||||||
|
@ -536,7 +541,7 @@ export default function Gallery() {
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
await syncWithRemote(false, true);
|
await syncWithRemote(false, true);
|
||||||
loadingBar.current.complete();
|
finishLoading();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -549,9 +554,9 @@ export default function Gallery() {
|
||||||
const downloadHelper = async () => {
|
const downloadHelper = async () => {
|
||||||
const selectedFiles = getSelectedFiles(selected, files);
|
const selectedFiles = getSelectedFiles(selected, files);
|
||||||
clearSelection();
|
clearSelection();
|
||||||
!syncInProgress.current && loadingBar.current?.continuousStart();
|
startLoading();
|
||||||
await downloadFiles(selectedFiles);
|
await downloadFiles(selectedFiles);
|
||||||
!syncInProgress.current && loadingBar.current.complete();
|
finishLoading();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -609,7 +614,8 @@ export default function Gallery() {
|
||||||
syncWithRemote={syncWithRemote}
|
syncWithRemote={syncWithRemote}
|
||||||
setDialogMessage={setDialogMessage}
|
setDialogMessage={setDialogMessage}
|
||||||
setCollectionNamerAttributes={setCollectionNamerAttributes}
|
setCollectionNamerAttributes={setCollectionNamerAttributes}
|
||||||
startLoadingBar={loadingBar.current?.continuousStart}
|
startLoading={startLoading}
|
||||||
|
finishLoading={finishLoading}
|
||||||
collectionFilesCount={collectionFilesCount}
|
collectionFilesCount={collectionFilesCount}
|
||||||
/>
|
/>
|
||||||
<CollectionNamer
|
<CollectionNamer
|
||||||
|
|
|
@ -6,12 +6,15 @@ import {
|
||||||
removeFromCollection,
|
removeFromCollection,
|
||||||
restoreToCollection,
|
restoreToCollection,
|
||||||
} from 'services/collectionService';
|
} from 'services/collectionService';
|
||||||
import { getSelectedFiles } from 'utils/file';
|
import { downloadFiles, getSelectedFiles } from 'utils/file';
|
||||||
import { File } from 'services/fileService';
|
import { File, getLocalFiles } from 'services/fileService';
|
||||||
import { CustomError } from 'utils/common/errorUtil';
|
import { CustomError } from 'utils/common/errorUtil';
|
||||||
import { SelectedState } from 'pages/gallery';
|
import { SelectedState } from 'pages/gallery';
|
||||||
import { User } from 'services/userService';
|
import { User } from 'services/userService';
|
||||||
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
||||||
|
import { SetDialogMessage } from 'components/MessageDialog';
|
||||||
|
import { logError } from 'utils/sentry';
|
||||||
|
import constants from 'utils/strings/constants';
|
||||||
|
|
||||||
export enum COLLECTION_OPS_TYPE {
|
export enum COLLECTION_OPS_TYPE {
|
||||||
ADD,
|
ADD,
|
||||||
|
@ -83,3 +86,23 @@ export function isFavoriteCollection(
|
||||||
return collection.type === CollectionType.favorites;
|
return collection.type === CollectionType.favorites;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function downloadCollection(
|
||||||
|
collectionID: number,
|
||||||
|
setDialogMessage: SetDialogMessage
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const allFiles = await getLocalFiles();
|
||||||
|
const collectionFiles = allFiles.filter(
|
||||||
|
(file) => file.collectionID === collectionID
|
||||||
|
);
|
||||||
|
await downloadFiles(collectionFiles);
|
||||||
|
} catch (e) {
|
||||||
|
logError(e, 'download collection failed ');
|
||||||
|
setDialogMessage({
|
||||||
|
title: constants.ERROR,
|
||||||
|
content: constants.DELETE_COLLECTION_FAILED,
|
||||||
|
close: { variant: 'danger' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -382,6 +382,14 @@ const englishConstants = {
|
||||||
`oops, you're already sharing this with ${email}`,
|
`oops, you're already sharing this with ${email}`,
|
||||||
SHARING_BAD_REQUEST_ERROR: 'sharing album not allowed',
|
SHARING_BAD_REQUEST_ERROR: 'sharing album not allowed',
|
||||||
SHARING_DISABLED_FOR_FREE_ACCOUNTS: 'sharing is disabled for free accounts',
|
SHARING_DISABLED_FOR_FREE_ACCOUNTS: 'sharing is disabled for free accounts',
|
||||||
|
CONFIRM_DOWNLOAD_COLLECTION: 'download album',
|
||||||
|
DOWNLOAD_COLLECTION_MESSAGE: () => (
|
||||||
|
<>
|
||||||
|
<p>are you sure you want to download the complete album?</p>
|
||||||
|
<p>all files will be queued for download sequentially</p>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
DOWNLOAD_COLLECTION_FAILED: 'album downloading failed, please try again',
|
||||||
CREATE_ALBUM_FAILED: 'failed to create album , please try again',
|
CREATE_ALBUM_FAILED: 'failed to create album , please try again',
|
||||||
SEARCH_HINT: () => (
|
SEARCH_HINT: () => (
|
||||||
<span>try searching for New York, April 14, Christmas...</span>
|
<span>try searching for New York, April 14, Christmas...</span>
|
||||||
|
|
Loading…
Reference in a new issue