Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor code

Abhinav22605e503c9b
diff --git a/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipant.tsx b/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipant.tsx
index 17dbf9463d..94b356612f 100644
--- a/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipant.tsx
+++ b/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipant.tsx
@@ -39,23 +39,29 @@ export default function AddParticipant({
[emailList, collection.sharees]
);
- const collectionShare: AddParticipantFormProps['callback'] = async (
- emails
- ) => {
- if (emails.length === 1) {
- if (emails[0] === user.email) {
+ const collectionShare: AddParticipantFormProps['callback'] = async ({
+ email,
+ emails,
+ }) => {
+ // if email is provided, means user has custom entered email, so, will need to validate for self sharing
+ // and already shared
+ if (email) {
+ if (email === user.email) {
throw new Error(t('SHARE_WITH_SELF'));
} else if (
- collection?.sharees?.find((value) => value.email === emails[0])
+ collection?.sharees?.find((value) => value.email === email)
) {
- throw new Error(t('ALREADY_SHARED', { email: emails[0] }));
+ throw new Error(t('ALREADY_SHARED', { email: email }));
}
+ // set emails to array of one email
+ emails = [email];
}
for (const email of emails) {
if (
email === user.email ||
collection?.sharees?.find((value) => value.email === email)
) {
+ // can just skip this email
continue;
}
try {
diff --git a/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx b/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx
index ccda4c13ee..f4e3cd639f 100644
--- a/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx
+++ b/apps/photos/src/components/Collections/CollectionShare/emailShare/AddParticipantForm.tsx
@@ -18,7 +18,7 @@ interface formValues {
selectedOptions: string[];
}
export interface AddParticipantFormProps {
- callback: (emails: string[]) => Promise<void>;
+ callback: (props: { email?: string; emails?: string[] }) => Promise<void>;
fieldType: 'text' | 'email' | 'password';
placeholder: string;
buttonText: string;
@@ -49,9 +49,9 @@ export default function AddParticipantForm(props: AddParticipantFormProps) {
try {
SetLoading(true);
if (values.inputValue !== '') {
- await props.callback([values.inputValue]);
+ await props.callback({ email: values.inputValue });
} else if (values.selectedOptions.length !== 0) {
- await props.callback(values.selectedOptions);
+ await props.callback({ emails: values.selectedOptions });
}
SetLoading(false);
props.onClose();