[mob][photos] Refactor

This commit is contained in:
ashilkn
2025-01-23 21:09:24 +05:30
parent c7bc8e97d5
commit 065c13cd06
4 changed files with 32 additions and 34 deletions

View File

@@ -228,6 +228,10 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
Navigator.of(context).pop(newEmail);
} catch (e) {
await showGenericErrorDialog(
context: context,
error: e,
);
_logger.severe("Failed to link email to person", e);
}
}
@@ -330,7 +334,7 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
String personID,
BuildContext context,
) async {
if (await checkIfEmailAlreadyAssignedToAPerson(context, email)) {
if (await checkIfEmailAlreadyAssignedToAPerson(email)) {
throw Exception("Email already linked to a person");
}

View File

@@ -118,18 +118,17 @@ class _LinkContactToPersonSelectionPageState
return _RoundedPersonFaceWidget(
onTap: () async {
try {
unawaited(
linkPersonToContact(
context,
emailToLink: widget.emailToLink!,
personEntity: results[index].person,
).then((updatedPerson) {
if (updatedPerson != null) {
Navigator.of(context).pop(updatedPerson);
}
}),
final updatedPerson = await linkPersonToContact(
context,
emailToLink: widget.emailToLink!,
personEntity: results[index].person,
);
if (updatedPerson != null) {
Navigator.of(context).pop(updatedPerson);
}
} catch (e) {
await showGenericErrorDialog(context: context, error: e);
_logger.severe("Failed to link person to contact", e);
}
},
@@ -149,8 +148,8 @@ class _LinkContactToPersonSelectionPageState
required String emailToLink,
required PersonEntity personEntity,
}) async {
if (await checkIfEmailAlreadyAssignedToAPerson(context, emailToLink)) {
throw Exception("Email already linked");
if (await checkIfEmailAlreadyAssignedToAPerson(emailToLink)) {
throw Exception("Email already linked to a person");
}
final personName = personEntity.data.name;

View File

@@ -330,7 +330,10 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
clusterID: widget.clusterID!,
birthdate: _selectedDate,
email: _email,
);
).catchError((e) {
_logger.severe("Error adding new person", e);
return null;
});
if (newPersonEntity != null) {
Navigator.pop(context, newPersonEntity);
}
@@ -380,11 +383,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
shouldStickToDarkTheme: true,
onTap: () async {
if (widget.isEditing) {
try {
updatedPersonEntity = await updatePerson(context);
} catch (e) {
_logger.severe("Error updating person", e);
}
updatedPersonEntity = await updatePerson(context);
} else {
try {
updatedPersonEntity = await addNewPerson(
@@ -541,9 +540,17 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
}) async {
if (email != null &&
email.isNotEmpty &&
await checkIfEmailAlreadyAssignedToAPerson(context, email)) {
throw Exception("Email already assigned to a person");
await checkIfEmailAlreadyAssignedToAPerson(email)) {
_logger.severe(
"Failed to addNewPerson, email is already assigned to a person",
);
await showGenericErrorDialog(
context: context,
error: "Email already assigned",
);
return null;
}
try {
if (userAlreadyAssigned) {
return null;
@@ -593,7 +600,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
if (_email != null &&
_email!.isNotEmpty &&
_email != person!.data.email &&
await checkIfEmailAlreadyAssignedToAPerson(context, _email!)) {
await checkIfEmailAlreadyAssignedToAPerson(_email!)) {
throw Exception("Email already assigned to a person");
}
final String name = _inputName.trim();

View File

@@ -1,23 +1,11 @@
import "dart:io";
import "package:flutter/material.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import "package:photos/utils/dialog_util.dart";
Future<bool> checkIfEmailAlreadyAssignedToAPerson(
BuildContext context,
String email,
) async {
final persons = await PersonService.instance.getPersons();
for (var person in persons) {
if (person.data.email == email) {
await showErrorDialog(
context,
"Email already linked",
"This email is already linked to a person",
useRootNavigator: Platform.isIOS,
);
return true;
}
}