Skip to content

Commit

Permalink
simplify contact details state
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed May 31, 2024
1 parent 634975c commit b5e1b7c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
12 changes: 2 additions & 10 deletions lib/ui/contact_details/cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ part 'state.dart';

class ContactDetailsCubit extends Cubit<ContactDetailsState> {
ContactDetailsCubit(this.contactsRepository, String coagContactId)
: super(ContactDetailsState(coagContactId, ContactDetailsStatus.success,
: super(ContactDetailsState(ContactDetailsStatus.success,
contactsRepository.getContact(coagContactId),
circles:
(contactsRepository.getCircleMemberships()[coagContactId] ?? [])
Expand All @@ -35,10 +35,7 @@ class ContactDetailsCubit extends Cubit<ContactDetailsState> {
});
_contactsSuscription = contactsRepository.getContactUpdates().listen((c) {
if (c.coagContactId == coagContactId && !isClosed) {
emit(state.copyWith(
coagContactId: c.coagContactId,
status: ContactDetailsStatus.success,
contact: c));
emit(state.copyWith(status: ContactDetailsStatus.success, contact: c));
}
});

Expand Down Expand Up @@ -69,11 +66,6 @@ class ContactDetailsCubit extends Cubit<ContactDetailsState> {
await contactsRepository.updateContact(updatedContact);
}

// TODO: Figure out better way to set the shareprofile to null again
// The solution is probably adding profile sharing filters and then switching this to a filter that doesn't let anything through?
Future<void> unshare() async => contactsRepository
.updateContact(state.contact!.copyWith(sharedProfile: ''));

Future<void> delete(String coagContactId) async =>
contactsRepository.removeContact(coagContactId);

Expand Down
7 changes: 0 additions & 7 deletions lib/ui/contact_details/cubit.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions lib/ui/contact_details/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,29 @@ extension ContactDetailsStatusX on ContactDetailsStatus {

@JsonSerializable()
final class ContactDetailsState extends Equatable {
const ContactDetailsState(this.coagContactId, this.status, this.contact,
{this.sharedProfile, this.circles = const []});
const ContactDetailsState(this.status, this.contact,
{this.circles = const []});

factory ContactDetailsState.fromJson(Map<String, dynamic> json) =>
_$ContactDetailsStateFromJson(json);

// TODO: We only need to contact not also the id, right?
final String coagContactId;
final CoagContact contact;
final ContactDetailsStatus status;
final CoagContact? sharedProfile;
final List<String> circles;

Map<String, dynamic> toJson() => _$ContactDetailsStateToJson(this);

ContactDetailsState copyWith({
String? coagContactId,
ContactDetailsStatus? status,
CoagContact? contact,
CoagContact? sharedProfile,
List<String>? circles,
}) =>
ContactDetailsState(
coagContactId ?? this.coagContactId,
status ?? this.status,
contact ?? this.contact,
sharedProfile: sharedProfile ?? this.sharedProfile,
circles: circles ?? this.circles,
);

@override
List<Object?> get props =>
[coagContactId, contact, sharedProfile, status, circles];
List<Object?> get props => [contact, status, circles];
}

0 comments on commit b5e1b7c

Please sign in to comment.