Skip to content

Commit

Permalink
fix circles form state update and add on empty text
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed May 14, 2024
1 parent 8109a2f commit 509b47f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
29 changes: 18 additions & 11 deletions lib/ui/widgets/circles/cubit.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2024 The Coagulate Authors. All rights reserved.
// SPDX-License-Identifier: MPL-2.0

import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
Expand All @@ -11,22 +13,21 @@ import '../../../data/repositories/contacts.dart';
part 'cubit.g.dart';
part 'state.dart';

// TODO: Do we need this layer inbetween the repo and the ui?
class CirclesCubit extends Cubit<CirclesState> {
CirclesCubit(this.contactsRepository, this.coagContactId)
: super(CirclesState(contactsRepository
.getCircles()
.map((id, label) => MapEntry(id, (
id,
label,
contactsRepository.getCircleMemberships()[id]?.contains(id) ??
false
)))
.values
.toList()));
: super(CirclesState(
contactsRepository.circlesWithMembership(coagContactId))) {
_circlesSubscription = contactsRepository.getCirclesUpdates().listen((c) {
if (!isClosed) {
emit(CirclesState(
contactsRepository.circlesWithMembership(coagContactId)));
}
});
}

final ContactsRepository contactsRepository;
final String coagContactId;
late final StreamSubscription<void> _circlesSubscription;

void update(List<(String, String, bool)> circles) {
// Check if there is a new circle, add it
Expand All @@ -45,4 +46,10 @@ class CirclesCubit extends Cubit<CirclesState> {
circles.where((c) => c.$3).map((c) => c.$1).asList();
contactsRepository.updateCircleMemberships(memberships);
}

@override
Future<void> close() {
_circlesSubscription.cancel();
return super.close();
}
}
3 changes: 2 additions & 1 deletion lib/ui/widgets/circles/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class _CirclesFormState extends State<CirclesForm> {
)),
IconButton(
key: const Key('circlesForm_submitNewCircle'),
onPressed: _addNewCircle,
onPressed:
(_titleController.text.isEmpty) ? null : _addNewCircle,
icon: const Icon(Icons.add),
),
])),
Expand Down

0 comments on commit 509b47f

Please sign in to comment.