Skip to content

Commit

Permalink
Fix message that a repo already exists when it's being created
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed Aug 16, 2024
1 parent 6796fbe commit 20bfd6d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/app/cubits/repo_creation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ class RepoCreationFailure extends RepoCreationSubstate {

class RepoCreationCubit extends Cubit<RepoCreationState> with AppLogger {
RepoCreationCubit({required this.reposCubit}) : super(RepoCreationState()) {
nameController.addListener(
() => unawaited(_onNameChanged(nameController.text)),
);
nameController.addListener(_onNameChangedUnawaited);

setLocalSecret(LocalSecretRandom());
}
Expand Down Expand Up @@ -221,6 +219,13 @@ class RepoCreationCubit extends Cubit<RepoCreationState> with AppLogger {
}

Future<void> save() async {
// On some devices the `_onNameChangedUnawaited` listener is still called
// after this `save` function is called. When that happens and we already
// created the repository, it'll complain that the repository with the name
// in the `nameController` already exists, even though it's this cubit that
// created it. So we remove the listener to not pester the user.
nameController.removeListener(_onNameChangedUnawaited);

final substate = state.substate;
if (substate is! RepoCreationValid) {
return;
Expand Down Expand Up @@ -272,7 +277,13 @@ class RepoCreationCubit extends Cubit<RepoCreationState> with AppLogger {
}
}

Future<void> _onNameChanged(String name) async {
void _onNameChangedUnawaited() {
unawaited(_onNameChanged());
}

Future<void> _onNameChanged() async {
final name = nameController.text;

if (name.isEmpty) {
if (state.location != null) {
_setInvalidName(S.current.messageErrorFormValidatorNameDefault);
Expand Down

0 comments on commit 20bfd6d

Please sign in to comment.