refactor code

This commit is contained in:
abhinav-grd 2021-09-22 17:51:52 +05:30
parent e3021dcf55
commit 0675182177

View file

@ -370,49 +370,17 @@ export default function Gallery() {
}); });
} }
}; };
const archiveFilesHelper = async () => { const changeFilesVisibilityHelper = async (
visibility: VISIBILITY_STATE
) => {
loadingBar.current?.continuousStart(); loadingBar.current?.continuousStart();
try { try {
const archivedFiles = await changeFilesVisibility( const updatedFiles = await changeFilesVisibility(
files, files,
selected, selected,
VISIBILITY_STATE.ARCHIVED visibility
); );
await updateMagicMetadata(archivedFiles); await updateMagicMetadata(updatedFiles);
} catch (e) {
console.log(e);
switch (e.status?.toString()) {
case ServerErrorCodes.FORBIDDEN:
setDialogMessage({
title: constants.ERROR,
staticBackdrop: true,
close: { variant: 'danger' },
content: constants.NOT_FILE_OWNER,
});
return;
}
setDialogMessage({
title: constants.ERROR,
staticBackdrop: true,
close: { variant: 'danger' },
content: constants.UNKNOWN_ERROR,
});
} finally {
clearSelection();
syncWithRemote();
loadingBar.current.complete();
}
};
const unArchiveFilesHelper = async () => {
loadingBar.current?.continuousStart();
try {
const unarchiveFiles = await changeFilesVisibility(
files,
selected,
VISIBILITY_STATE.VISIBLE
);
await updateMagicMetadata(unarchiveFiles);
} catch (e) { } catch (e) {
switch (e.status?.toString()) { switch (e.status?.toString()) {
case ServerErrorCodes.FORBIDDEN: case ServerErrorCodes.FORBIDDEN:
@ -639,8 +607,16 @@ export default function Gallery() {
selected.collectionID === activeCollection && ( selected.collectionID === activeCollection && (
<SelectedFileOptions <SelectedFileOptions
addToCollectionHelper={addToCollectionHelper} addToCollectionHelper={addToCollectionHelper}
archiveFilesHelper={archiveFilesHelper} archiveFilesHelper={() =>
unArchiveFilesHelper={unArchiveFilesHelper} changeFilesVisibilityHelper(
VISIBILITY_STATE.ARCHIVED
)
}
unArchiveFilesHelper={() =>
changeFilesVisibilityHelper(
VISIBILITY_STATE.VISIBLE
)
}
moveToCollectionHelper={moveToCollectionHelper} moveToCollectionHelper={moveToCollectionHelper}
showCreateCollectionModal={ showCreateCollectionModal={
showCreateCollectionModal showCreateCollectionModal