Skip to content

Commit

Permalink
feat: members detail and remove members
Browse files Browse the repository at this point in the history
  • Loading branch information
borgoat committed Nov 17, 2024
1 parent 74f743a commit eee991b
Show file tree
Hide file tree
Showing 21 changed files with 648 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ SPEC CHECKSUMS:
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
phone_number: 567a167933138df1080eb0d8ecb0ea44f1dee1ed
PhoneNumberKit: 5b1be7ee4955dfeeb855f51eecdd829ab24b3484
PhoneNumberKit: 54a4e3f3c776b3277b084acf00e2da18ff548d58
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sign_in_with_apple: f3bf75217ea4c2c8b91823f225d70230119b8440
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
Expand Down
12 changes: 12 additions & 0 deletions lib/epics/members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ createMembersEpic(MembersRepository members) => combineEpics<AppState>([
_createUpdateMemberEpic(members),
_onNewMembersCreated,
_createRetrieveOwnMemberByGroupIdEpic(members),
_createDeleteOneMember(members),
]);

Epic<AppState> _createAddMembersToGroupEpic(MembersRepository members) {
Expand Down Expand Up @@ -67,3 +68,14 @@ Epic<AppState> _createRetrieveOwnMemberByGroupIdEpic(
FailRetrieveOne(id: groupId.toString(), error: error));
});
}

Epic<AppState> _createDeleteOneMember(MembersRepository members) {
return (Stream<dynamic> actions, EpicStore<AppState> store) =>
actions.whereType<RequestDeleteOne<Member>>().asyncMap((action) {
return members
.removeMember(int.parse(action.id))
.then<dynamic>((_) => SuccessDeleteOne<Member>(action.id))
.catchError(
(error) => FailDeleteOne<Member>(id: action.id, error: error));
});
}
14 changes: 14 additions & 0 deletions lib/go_router_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ part 'go_router_builder.g.dart';
// TODO Should be at root level?
TypedGoRoute<GroupScheduleCreateRoute>(path: 'schedule-create'),
TypedGoRoute<GroupScheduleDetailsRoute>(path: 'schedules/:scheduleId'),
TypedGoRoute<GroupMemberDetailsRoute>(path: 'members/:memberId'),
],
),
TypedGoRoute<SettingsRoute>(
Expand Down Expand Up @@ -121,6 +122,19 @@ class GroupScheduleDetailsRoute extends GoRouteData with AuthenticationGuard {
GroupScheduleDetailsContainer(groupId: groupId, scheduleId: scheduleId);
}

@immutable
class GroupMemberDetailsRoute extends GoRouteData with AuthenticationGuard {
final String groupId;
final String memberId;

const GroupMemberDetailsRoute(
{required this.groupId, required this.memberId});

@override
Widget build(BuildContext context, GoRouterState state) =>
GroupMemberDetailsContainer(groupId: groupId, memberId: memberId);
}

@immutable
class SelectContactsRoute extends GoRouteData with AuthenticationGuard {
@override
Expand Down
25 changes: 25 additions & 0 deletions lib/go_router_builder.g.dart

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

7 changes: 7 additions & 0 deletions lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@@locale": "de",
"appName": "AppFor.it",
"addContact": "Kontakt hinzufügen",
"addInvite": "Einladung hinzufügen",
"camera": "Kamera",
"cancel": "Abbrechen",
"changeTheme": "Thema",
Expand All @@ -25,8 +26,14 @@
"eventName": "Name des Events",
"events": "Events",
"gallery": "Galerie",
"groupDismissAdmin": "Admin entfernen",
"groupMakeAdmin": "Zum Gruppenadmin machen",
"grantPermission": "Berechtigung erteilen",
"groupRemoveMember": "Aus Gruppe entfernen",
"groupRemoveConfirmation": "Bist du sicher, dass du dieses Mitglied aus der Gruppe entfernen möchtest?",
"groupRoles": "{role, select, admin{Admin} member{Mitglied} other{Unbekannt}}",
"invite": "Mitglieder einladen",
"invites": "Einladungen",
"inviteFromContacts": "Aus Kontakten einladen",
"inviteManual": "Manuell einladen",
"inviteMembersCTA": "Lad' ein paar Freunde ein!",
Expand Down
15 changes: 15 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@@locale": "en",
"appName": "AppFor.it",
"addContact": "Add contact",
"addInvite": "Add invite",
"camera": "Camera",
"cancel": "Cancel",
"changeTheme": "Theme",
Expand All @@ -25,8 +26,22 @@
"eventName": "Event name",
"events": "Events",
"gallery": "Gallery",
"groupDismissAdmin": "Dismiss as admin",
"groupMakeAdmin": "Make group admin",
"grantPermission": "Grant permission",
"groupRemoveMember": "Remove from group",
"groupRemoveConfirmation": "Are you sure you want to remove this member from the group?",
"groupRoles": "{role, select, admin{Admin} member{Member} other{Unknown}}",
"@groupRoles": {
"description": "Member roles in a group",
"placeholders": {
"role": {
"type": "String"
}
}
},
"invite": "Invite members",
"invites": "Invites",
"inviteFromContacts": "Invite from contacts",
"inviteManual": "Invite manually",
"inviteMembersCTA": "Invite some friends!",
Expand Down
7 changes: 7 additions & 0 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@@locale": "es",
"appName": "AppFor.it",
"addContact": "Añade un contacto",
"addInvite": "Añade una invitación",
"camera": "Cámara",
"cancel": "Cancela",
"changeTheme": "Tema",
Expand All @@ -25,8 +26,14 @@
"eventName": "Nombre del evento",
"events": "Eventos",
"gallery": "Galería",
"groupDismissAdmin": "Descarta como admin",
"groupMakeAdmin": "Haz admin del grupo",
"grantPermission": "Da permiso",
"groupRemoveMember": "Quita del grupo",
"groupRemoveConfirmation": "¿Seguro que quieres quitar a este miembro del grupo?",
"groupRoles": "{role, select, admin{Admin} member{Miembro} other{Desconocido}}",
"invite": "Invita a la gente",
"invites": "Invitaciones",
"inviteFromContacts": "Invita desde tus contactos",
"inviteManual": "Invita manualmente",
"inviteMembersCTA": "¡Invita a algunos amigos!",
Expand Down
7 changes: 7 additions & 0 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@@locale": "fr",
"appName": "AppFor.it",
"addContact": "Ajoute un contact",
"addInvite": "Ajoute une invitation",
"camera": "Caméra",
"cancel": "Annule",
"changeTheme": "Thème",
Expand All @@ -25,8 +26,14 @@
"eventName": "Nom de l'événement",
"events": "Événements",
"gallery": "Galerie",
"groupDismissAdmin": "Révoque l'admin",
"groupMakeAdmin": "Rend admin du groupe",
"grantPermission": "Donne la permission",
"groupRemoveMember": "Retire du groupe",
"groupRemoveConfirmation": "Es-tu sûr de vouloir retirer ce membre du groupe?",
"groupRoles": "{role, select, admin{Admin} member{Membre} other{Inconnu}}",
"invite": "Invite des gens",
"invites": "Invitations",
"inviteFromContacts": "Invite depuis tes contacts",
"inviteManual": "Invite manuellement",
"inviteMembersCTA": "Invite quelques amis!",
Expand Down
7 changes: 7 additions & 0 deletions lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@@locale": "it",
"appName": "AppFor.it",
"addContact": "Aggiungi contatto",
"addInvite": "Aggiungi invito",
"camera": "Fotocamera",
"cancel": "Annulla",
"changeTheme": "Tema",
Expand All @@ -25,8 +26,14 @@
"eventName": "Nome dell'evento",
"events": "Eventi",
"gallery": "Galleria",
"groupDismissAdmin": "Rimuovi come amministratore",
"groupMakeAdmin": "Rendi amministratore del gruppo",
"grantPermission": "Dai il permesso",
"groupRemoveMember": "Rimuovi dal gruppo",
"groupRemoveConfirmation": "Sei sicuro di voler rimuovere questo membro dal gruppo?",
"groupRoles": "{role, select, admin{Admin} member{Membro} other{Sconosciuto}}",
"invite": "Invita la gente",
"invites": "Inviti",
"inviteFromContacts": "Invita dai tuoi contatti",
"inviteManual": "Invita manualmente",
"inviteMembersCTA": "Invita qualche amico!",
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/containers/containers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export 'group_details.dart';
export 'group_events.dart';
export 'group_form.dart';
export 'group_manage.dart';
export 'group_member_details.dart';
export 'group_members.dart';
export 'group_schedule_details.dart';
export 'home.dart';
Expand Down
79 changes: 79 additions & 0 deletions lib/presentation/containers/group_member_details.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:flutter/foundation.dart'; // ignore: unused_import
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:parousia/actions/actions.dart';
import 'package:parousia/models/models.dart';
import 'package:parousia/presentation/presentation.dart';
import 'package:parousia/state/state.dart';
import 'package:redux/redux.dart';
import 'package:redux_entity/redux_entity.dart';

part 'group_member_details.freezed.dart';

class GroupMemberDetailsContainer extends StatelessWidget {
final String groupId;
final String memberId;

const GroupMemberDetailsContainer({
super.key,
required this.groupId,
required this.memberId,
});

@override
Widget build(BuildContext context) {
return StoreConnector<AppState, _ViewModel>(
distinct: true,
converter: (store) => _ViewModel.fromStore(store, groupId, memberId),
onInit: (store) => store.dispatch(GroupDetailsOpenAction(groupId)),
builder: (context, vm) => GroupMemberDetailsScreen(
loading: vm.loading,
group: vm.group,
member: vm.member,
profile: vm.profile,
invites: vm.invites,
onRemove: vm.onRemove,
),
);
}
}

@freezed
sealed class _ViewModel with _$ViewModel {
const factory _ViewModel({
required bool loading,
Group? group,
Member? member,
Profile? profile,
List<Invite>? invites,
OnRemoveFromGroupCallback? onRemove,
}) = __ViewModel;

static _ViewModel fromStore(
Store<AppState> store, String groupId, String memberId) {
final group = store.state.groups.entities[groupId];

if (group == null) {
return const _ViewModel(loading: true);
}

// TODO: should use selectors
final member = store.state.members.entities[memberId];
final profile = store.state.profiles.entities[member?.profileId];
final invites = store.state.invites.entities.values
.where((invite) => invite.memberId.toString() == memberId)
.toList();

return _ViewModel(
loading: store.state.groups.loadingAll ||
(store.state.groups.loadingIds[groupId] ?? false),
group: group,
member: member,
profile: profile,
invites: invites,
onRemove: (member) =>
store.dispatch(RequestDeleteOne<Member>(member.id.toString())),
);
}
}
Loading

0 comments on commit eee991b

Please sign in to comment.