Merge pull request #63 from ente-io/dummy-loader-from-delete
Dummy loader for operation
This commit is contained in:
commit
0d922d6958
|
@ -9,7 +9,7 @@ export interface MessageAttributes {
|
|||
close?: { text?: string; variant?: string };
|
||||
proceed?: {
|
||||
text: string;
|
||||
action: any;
|
||||
action: () => void;
|
||||
variant: string;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
|
|
@ -7,7 +7,7 @@ import SubmitButton from 'components/SubmitButton';
|
|||
import MessageDialog from 'components/MessageDialog';
|
||||
|
||||
export interface CollectionNamerAttributes {
|
||||
callback: (name) => Promise<void>;
|
||||
callback: (name) => void;
|
||||
title: string;
|
||||
autoFilledName: string;
|
||||
buttonText: string;
|
||||
|
|
|
@ -16,6 +16,7 @@ interface Props {
|
|||
collections: Collection[];
|
||||
selectedCollectionID: number;
|
||||
setDialogMessage: SetDialogMessage;
|
||||
startLoadingBar: () => void;
|
||||
showCollectionShareModal: () => void;
|
||||
redirectToAll: () => void;
|
||||
}
|
||||
|
@ -37,15 +38,42 @@ const CollectionOptions = (props: Props) => {
|
|||
props.selectedCollectionID,
|
||||
props.collections
|
||||
)?.name,
|
||||
callback: collectionRename.bind(
|
||||
null,
|
||||
getSelectedCollection(
|
||||
props.selectedCollectionID,
|
||||
props.collections
|
||||
)
|
||||
),
|
||||
callback: (newName) => {
|
||||
props.startLoadingBar();
|
||||
collectionRename(
|
||||
getSelectedCollection(
|
||||
props.selectedCollectionID,
|
||||
props.collections
|
||||
),
|
||||
newName
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
const confirmDeleteCollection = () => {
|
||||
props.setDialogMessage({
|
||||
title: constants.CONFIRM_DELETE_COLLECTION,
|
||||
content: constants.DELETE_COLLECTION_MESSAGE(),
|
||||
staticBackdrop: true,
|
||||
proceed: {
|
||||
text: constants.DELETE_COLLECTION,
|
||||
action: () => {
|
||||
props.startLoadingBar();
|
||||
deleteCollection(
|
||||
props.selectedCollectionID,
|
||||
props.syncWithRemote,
|
||||
props.redirectToAll,
|
||||
props.setDialogMessage
|
||||
);
|
||||
},
|
||||
variant: 'danger',
|
||||
},
|
||||
close: {
|
||||
text: constants.CANCEL,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const MenuLink = (props) => (
|
||||
<LinkButton
|
||||
style={{ fontSize: '14px', fontWeight: 700, padding: '8px 1em' }}
|
||||
|
@ -82,28 +110,7 @@ const CollectionOptions = (props: Props) => {
|
|||
<MenuItem>
|
||||
<MenuLink
|
||||
variant="danger"
|
||||
onClick={() => {
|
||||
props.setDialogMessage({
|
||||
title: constants.CONFIRM_DELETE_COLLECTION,
|
||||
content: constants.DELETE_COLLECTION_MESSAGE(),
|
||||
staticBackdrop: true,
|
||||
proceed: {
|
||||
text: constants.DELETE_COLLECTION,
|
||||
action: deleteCollection.bind(
|
||||
null,
|
||||
|
||||
props.selectedCollectionID,
|
||||
|
||||
props.syncWithRemote,
|
||||
props.redirectToAll
|
||||
),
|
||||
variant: 'danger',
|
||||
},
|
||||
close: {
|
||||
text: constants.CANCEL,
|
||||
},
|
||||
});
|
||||
}}
|
||||
onClick={confirmDeleteCollection}
|
||||
>
|
||||
{constants.DELETE}
|
||||
</MenuLink>
|
||||
|
|
|
@ -17,7 +17,7 @@ export const CollectionIcon = styled.div`
|
|||
`;
|
||||
|
||||
export interface CollectionSelectorAttributes {
|
||||
callback: (collection) => Promise<void>;
|
||||
callback: (collection) => void;
|
||||
showNextModal: () => void;
|
||||
title: string;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { SetDialogMessage } from 'components/MessageDialog';
|
|||
import NavigationButton, {
|
||||
SCROLL_DIRECTION,
|
||||
} from 'components/navigationButton';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { OverlayTrigger } from 'react-bootstrap';
|
||||
import { Collection, CollectionType } from 'services/collectionService';
|
||||
import { User } from 'services/userService';
|
||||
|
@ -21,6 +21,7 @@ interface CollectionProps {
|
|||
setDialogMessage: SetDialogMessage;
|
||||
syncWithRemote: () => Promise<void>;
|
||||
setCollectionNamerAttributes: SetCollectionNamerAttributes;
|
||||
startLoadingBar: () => void;
|
||||
}
|
||||
|
||||
const Container = styled.div`
|
||||
|
@ -71,13 +72,19 @@ const Chip = styled.button<{ active: boolean }>`
|
|||
|
||||
export default function Collections(props: CollectionProps) {
|
||||
const { selected, collections, selectCollection } = props;
|
||||
const [selectedCollectionID, setSelectedCollectionID] = useState<number>(
|
||||
null
|
||||
);
|
||||
const [selectedCollectionID, setSelectedCollectionID] =
|
||||
useState<number>(null);
|
||||
const collectionRef = useRef<HTMLDivElement>(null);
|
||||
const [collectionShareModalView, setCollectionShareModalView] = useState(
|
||||
false
|
||||
);
|
||||
const [collectionShareModalView, setCollectionShareModalView] =
|
||||
useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!collectionRef?.current) {
|
||||
return;
|
||||
}
|
||||
collectionRef.current.scrollLeft = 0;
|
||||
}, [collections]);
|
||||
|
||||
const clickHandler = (collection?: Collection) => () => {
|
||||
setSelectedCollectionID(collection?.id);
|
||||
selectCollection(collection?.id);
|
||||
|
@ -93,6 +100,7 @@ export default function Collections(props: CollectionProps) {
|
|||
collections: props.collections,
|
||||
selectedCollectionID,
|
||||
setDialogMessage: props.setDialogMessage,
|
||||
startLoadingBar: props.startLoadingBar,
|
||||
showCollectionShareModal: setCollectionShareModalView.bind(null, true),
|
||||
redirectToAll: selectCollection.bind(null, null),
|
||||
});
|
||||
|
@ -127,7 +135,7 @@ export default function Collections(props: CollectionProps) {
|
|||
>
|
||||
{item.name}
|
||||
{item.type != CollectionType.favorites &&
|
||||
item.owner.id === user?.id ? (
|
||||
item.owner.id === user?.id ? (
|
||||
<OverlayTrigger
|
||||
rootClose
|
||||
trigger="click"
|
||||
|
|
|
@ -276,13 +276,11 @@ function PlanSelector(props: Props) {
|
|||
)}
|
||||
<LinkButton
|
||||
variant="primary"
|
||||
onClick={(event) =>
|
||||
updatePaymentMethod(
|
||||
event,
|
||||
props.setDialogMessage,
|
||||
props.setLoading
|
||||
)
|
||||
}
|
||||
onClick={updatePaymentMethod.bind(
|
||||
null,
|
||||
props.setDialogMessage,
|
||||
props.setLoading
|
||||
)}
|
||||
style={{ marginTop: '20px' }}
|
||||
>
|
||||
{constants.MANAGEMENT_PORTAL}
|
||||
|
|
|
@ -6,11 +6,11 @@ import constants from 'utils/strings/constants';
|
|||
import { SetCollectionSelectorAttributes } from './CollectionSelector';
|
||||
|
||||
interface Props {
|
||||
addToCollectionHelper: (collectionName, collection) => Promise<void>;
|
||||
addToCollectionHelper: (collectionName, collection) => void;
|
||||
showCreateCollectionModal: () => void;
|
||||
setDialogMessage: SetDialogMessage;
|
||||
setCollectionSelectorAttributes: SetCollectionSelectorAttributes;
|
||||
deleteFileHelper: () => Promise<void>;
|
||||
deleteFileHelper: () => void;
|
||||
}
|
||||
const SelectedFileOptions = ({
|
||||
addToCollectionHelper,
|
||||
|
|
|
@ -218,15 +218,22 @@ export default function Gallery() {
|
|||
if (!files) {
|
||||
return <div />;
|
||||
}
|
||||
const addToCollectionHelper = addFilesToCollection.bind(
|
||||
null,
|
||||
setCollectionSelectorView,
|
||||
selected,
|
||||
files,
|
||||
clearSelection,
|
||||
syncWithRemote,
|
||||
selectCollection
|
||||
);
|
||||
const addToCollectionHelper = (
|
||||
collectionName: string,
|
||||
collection: Collection
|
||||
) => {
|
||||
loadingBar.current?.continuousStart();
|
||||
addFilesToCollection(
|
||||
setCollectionSelectorView,
|
||||
selected,
|
||||
files,
|
||||
clearSelection,
|
||||
syncWithRemote,
|
||||
selectCollection,
|
||||
collectionName,
|
||||
collection
|
||||
);
|
||||
};
|
||||
|
||||
const showCreateCollectionModal = () =>
|
||||
setCollectionNamerAttributes({
|
||||
|
@ -237,12 +244,14 @@ export default function Gallery() {
|
|||
addToCollectionHelper(collectionName, null),
|
||||
});
|
||||
|
||||
const deleteFileHelper = () =>
|
||||
const deleteFileHelper = () => {
|
||||
loadingBar.current?.continuousStart();
|
||||
deleteFiles(
|
||||
getSelectedFileIds(selected),
|
||||
clearSelection,
|
||||
syncWithRemote
|
||||
);
|
||||
};
|
||||
return (
|
||||
<FullScreenDropZone
|
||||
getRootProps={getRootProps}
|
||||
|
@ -282,6 +291,7 @@ export default function Gallery() {
|
|||
syncWithRemote={syncWithRemote}
|
||||
setDialogMessage={setDialogMessage}
|
||||
setCollectionNamerAttributes={setCollectionNamerAttributes}
|
||||
startLoadingBar={loadingBar.current?.continuousStart}
|
||||
/>
|
||||
<CollectionNamer
|
||||
show={collectionNamerView}
|
||||
|
|
|
@ -8,7 +8,8 @@ import { B64EncryptionResult } from './uploadService';
|
|||
import { getActualKey, getToken } from 'utils/common/key';
|
||||
import { getPublicKey, User } from './userService';
|
||||
import CryptoWorker from 'utils/crypto';
|
||||
import { errorCodes, ErrorHandler } from 'utils/common/errorUtil';
|
||||
import { SetDialogMessage } from 'components/MessageDialog';
|
||||
import constants from 'utils/strings/constants';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
|
||||
|
@ -386,7 +387,8 @@ const removeFromCollection = async (collection: Collection, files: File[]) => {
|
|||
export const deleteCollection = async (
|
||||
collectionID: number,
|
||||
syncWithRemote: () => Promise<void>,
|
||||
redirectToAll: () => void
|
||||
redirectToAll: () => void,
|
||||
setDialogMessage: SetDialogMessage
|
||||
) => {
|
||||
try {
|
||||
const token = getToken();
|
||||
|
@ -401,6 +403,11 @@ export const deleteCollection = async (
|
|||
redirectToAll();
|
||||
} catch (e) {
|
||||
console.error('delete collection failed ', e);
|
||||
setDialogMessage({
|
||||
title: constants.ERROR,
|
||||
content: constants.DELETE_COLLECTION_FAILED,
|
||||
close: { variant: 'danger' },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -102,13 +102,12 @@ export async function updateSubscription(
|
|||
proceed: {
|
||||
text: constants.UPDATE_PAYMENT_METHOD,
|
||||
variant: 'success',
|
||||
action: (event) =>
|
||||
updatePaymentMethod.bind(
|
||||
null,
|
||||
event,
|
||||
setDialogMessage,
|
||||
setLoading
|
||||
),
|
||||
action: updatePaymentMethod.bind(
|
||||
null,
|
||||
|
||||
setDialogMessage,
|
||||
setLoading
|
||||
),
|
||||
},
|
||||
close: { text: constants.CANCEL },
|
||||
});
|
||||
|
@ -184,13 +183,11 @@ export async function activateSubscription(
|
|||
}
|
||||
|
||||
export async function updatePaymentMethod(
|
||||
event,
|
||||
setDialogMessage: SetDialogMessage,
|
||||
setLoading: SetLoading
|
||||
) {
|
||||
try {
|
||||
setLoading(true);
|
||||
event.preventDefault();
|
||||
await billingService.redirectToCustomerPortal();
|
||||
} catch (error) {
|
||||
setDialogMessage({
|
||||
|
|
|
@ -269,6 +269,7 @@ const englishConstants = {
|
|||
RENAME_COLLECTION: 'rename album',
|
||||
CONFIRM_DELETE_COLLECTION: 'confirm album deletion',
|
||||
DELETE_COLLECTION: 'delete album',
|
||||
DELETE_COLLECTION_FAILED: 'album deletion failed , please try again',
|
||||
DELETE_COLLECTION_MESSAGE: () => (
|
||||
<>
|
||||
<p>are you sure you want to delete this album?</p>
|
||||
|
|
Loading…
Reference in a new issue