forked from cwtch.im/cwtch-ui
fix importBundle error handling and dupping of events
This commit is contained in:
parent
191065f51c
commit
5d09341277
|
@ -1 +1 @@
|
|||
2022-07-22-12-41-v1.8.0-7-g7b3e842
|
||||
2022-08-13-14-33-v1.8.0-10-gb99e35e
|
|
@ -1 +1 @@
|
|||
2022-07-22-16-41-v1.8.0-7-g7b3e842
|
||||
2022-08-13-18-34-v1.8.0-10-gb99e35e
|
|
@ -5,13 +5,9 @@ class ErrorHandler extends ChangeNotifier {
|
|||
static const String successErrorType = "success";
|
||||
|
||||
// Add Contact Specific Errors...
|
||||
static const String addContactErrorPrefix = "addcontact";
|
||||
static const String changePasswordErrorPrefix = "changepassword";
|
||||
static const String invalidImportStringErrorType = "invalid_import_string";
|
||||
static const String contactAlreadyExistsErrorType = "contact_already_exists";
|
||||
bool invalidImportStringError = false;
|
||||
bool contactAlreadyExistsError = false;
|
||||
bool explicitAddContactSuccess = false;
|
||||
|
||||
// ChangePassword
|
||||
bool changePasswordError = false;
|
||||
|
@ -31,10 +27,6 @@ class ErrorHandler extends ChangeNotifier {
|
|||
bool deletedServerSuccess = false;
|
||||
|
||||
reset() {
|
||||
invalidImportStringError = false;
|
||||
contactAlreadyExistsError = false;
|
||||
explicitAddContactSuccess = false;
|
||||
|
||||
importBundleError = false;
|
||||
importBundleSuccess = false;
|
||||
|
||||
|
@ -57,9 +49,6 @@ class ErrorHandler extends ChangeNotifier {
|
|||
String errorType = parts[1];
|
||||
|
||||
switch (prefix) {
|
||||
case addContactErrorPrefix:
|
||||
handleAddContactError(errorType);
|
||||
break;
|
||||
case importBundleErrorPrefix:
|
||||
handleImportBundleError(errorType);
|
||||
break;
|
||||
|
@ -76,26 +65,6 @@ class ErrorHandler extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
handleAddContactError(String errorType) {
|
||||
// Reset add contact errors
|
||||
invalidImportStringError = false;
|
||||
contactAlreadyExistsError = false;
|
||||
explicitAddContactSuccess = false;
|
||||
|
||||
switch (errorType) {
|
||||
case invalidImportStringErrorType:
|
||||
invalidImportStringError = true;
|
||||
break;
|
||||
case contactAlreadyExistsErrorType:
|
||||
contactAlreadyExistsError = true;
|
||||
break;
|
||||
case successErrorType:
|
||||
explicitAddContactSuccess = true;
|
||||
importBundleSuccess = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
handleImportBundleError(String errorType) {
|
||||
// Reset add contact errors
|
||||
importBundleError = false;
|
||||
|
|
|
@ -36,6 +36,9 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
final ctrlrContact = TextEditingController(text: "");
|
||||
final ctrlrGroupName = TextEditingController(text: "");
|
||||
String server = "";
|
||||
// flutter textfield onChange often fires twice and since we need contexts, we can't easily use a controler/listener
|
||||
String lastContactValue = "";
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -144,34 +147,41 @@ class _AddContactViewState extends State<AddContactView> {
|
|||
),
|
||||
CwtchTextField(
|
||||
testKey: Key("txtAddP2P"),
|
||||
key: Key("txtAddP2P"),
|
||||
controller: ctrlrContact,
|
||||
validator: (value) {
|
||||
if (value == "") {
|
||||
return null;
|
||||
}
|
||||
if (globalErrorHandler.invalidImportStringError) {
|
||||
if (globalErrorHandler.importBundleError) {
|
||||
return AppLocalizations.of(context)!.invalidImportString;
|
||||
} else if (globalErrorHandler.contactAlreadyExistsError) {
|
||||
return AppLocalizations.of(context)!.contactAlreadyExists;
|
||||
} else if (globalErrorHandler.explicitAddContactSuccess) {}
|
||||
} else if (globalErrorHandler.importBundleSuccess) { return null; }
|
||||
return null;
|
||||
},
|
||||
onChanged: (String importBundle) async {
|
||||
var profileOnion = Provider.of<ProfileInfoState>(bcontext, listen: false).onion;
|
||||
Provider.of<FlwtchState>(bcontext, listen: false).cwtch.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
|
||||
if (lastContactValue != importBundle) {
|
||||
lastContactValue = importBundle;
|
||||
var profileOnion = Provider
|
||||
.of<ProfileInfoState>(bcontext, listen: false)
|
||||
.onion;
|
||||
Provider
|
||||
.of<FlwtchState>(bcontext, listen: false)
|
||||
.cwtch
|
||||
.ImportBundle(profileOnion, importBundle.replaceFirst("cwtch:", ""));
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (globalErrorHandler.importBundleSuccess) {
|
||||
// TODO: This isn't ideal, but because onChange can be fired during this future check
|
||||
// and because the context can change after being popped we have this kind of double assertion...
|
||||
// There is probably a better pattern to handle this...
|
||||
if (AppLocalizations.of(bcontext) != null) {
|
||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
|
||||
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
|
||||
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (globalErrorHandler.importBundleSuccess) {
|
||||
// TODO: This isn't ideal, but because onChange can be fired during this future check
|
||||
// and because the context can change after being popped we have this kind of double assertion...
|
||||
// There is probably a better pattern to handle this...
|
||||
if (AppLocalizations.of(bcontext) != null) {
|
||||
final snackBar = SnackBar(content: Text(AppLocalizations.of(bcontext)!.successfullAddedContact + importBundle));
|
||||
ScaffoldMessenger.of(bcontext).showSnackBar(snackBar);
|
||||
Navigator.popUntil(bcontext, (route) => route.settings.name == "conversations");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
hintText: '',
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue