Bearbeiten und Löschen von Gruppen #148

Merged
sneeex merged 20 commits from feature/118-bearbeiten-und-löschen-von-gruppen into development 2026-03-09 20:30:38 +00:00
Showing only changes of commit b0b039875a - Show all commits

View File

@@ -12,11 +12,13 @@ import 'package:tallee/presentation/widgets/player_selection.dart';
import 'package:tallee/presentation/widgets/text_input/text_input_field.dart';
class CreateGroupView extends StatefulWidget {
const CreateGroupView({super.key, this.groupToEdit});
const CreateGroupView({super.key, this.groupToEdit, this.onMembersChanged});
/// The group to edit, if any
final Group? groupToEdit;
final VoidCallback? onMembersChanged;
@override
State<CreateGroupView> createState() => _CreateGroupViewState();
}
@@ -70,49 +72,6 @@ class _CreateGroupViewState extends State<CreateGroupView> {
title: Text(
widget.groupToEdit == null ? loc.create_new_group : loc.edit_group,
),
actions: widget.groupToEdit == null
? []
: [
IconButton(
icon: const Icon(Icons.delete),
onPressed: () async {
if (widget.groupToEdit != null) {
showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(loc.delete_group),
content: Text(loc.this_cannot_be_undone),
actions: [
TextButton(
onPressed: () =>
Navigator.of(context).pop(false),
child: Text(loc.cancel),
),
TextButton(
onPressed: () =>
Navigator.of(context).pop(true),
child: Text(loc.delete),
),
],
),
).then((confirmed) async {
if (confirmed == true && context.mounted) {
bool success = await db.groupDao.deleteGroup(
groupId: widget.groupToEdit!.id,
);
if (!context.mounted) return;
if (success) {
Navigator.pop(context);
} else {
if (!mounted) return;
showSnackbar(message: loc.error_deleting_group);
}
}
});
}
},
),
],
),
body: SafeArea(
child: Column(
@@ -222,6 +181,8 @@ class _CreateGroupViewState extends State<CreateGroupView> {
groupId: widget.groupToEdit!.id,
newPlayers: selectedPlayers,
);
await deleteObsoleteMatchGroupRelations();
widget.onMembersChanged?.call();
}
final success = successfullNameChange && successfullMemberChange;
@@ -229,6 +190,24 @@ class _CreateGroupViewState extends State<CreateGroupView> {
return (success, updatedGroup);
}
Future<void> deleteObsoleteMatchGroupRelations() async {
sneeex marked this conversation as resolved Outdated

Kurzen doc comment nochmal zu dieser Methode vllt

Kurzen doc comment nochmal zu dieser Methode vllt
final matches = await db.matchDao.getAllMatches();
sneeex marked this conversation as resolved Outdated

Lieber Methode getMatchesToGroup() in groupDao.dart, kann ggf. später auch noch einmal verwendet werden

Lieber Methode `getMatchesToGroup()` in `groupDao.dart`, kann ggf. später auch noch einmal verwendet werden

hast das auch so gemacht

hast das auch so gemacht

habs von dir kopiert

habs von dir kopiert

wo hab ich das gemacht? File und Zeile

wo hab ich das gemacht? File und Zeile

hast das auch so gemacht, group detail view
grafik.png

hast das auch so gemacht, group detail view <img width="491" alt="grafik.png" src="attachments/ae2ff61f-bc2e-45fc-baa5-62254ff3a2e1">
101 KiB

ja aber da diese vorgehensweise jetzt mehr als einmal im code ist machts erst recht sinn dafür ne methode zu schreiben und entsprechende vorkommen zu ersetzen

ja aber da diese vorgehensweise jetzt mehr als einmal im code ist machts erst recht sinn dafür ne methode zu schreiben und entsprechende vorkommen zu ersetzen
final groupMatches = matches
.where((match) => match.group?.id == widget.groupToEdit!.id)
.toList();
final selectedPlayerIds = selectedPlayers.map((p) => p.id).toSet();
final relationshipsToDelete = groupMatches.where((match) {
return !match.players.any(
(player) => selectedPlayerIds.contains(player.id),
);
}).toList();
for (var match in relationshipsToDelete) {
await db.matchDao.deleteMatchGroup(matchId: match.id);
}
}
/// Displays a snackbar with the given message and optional action.
///
/// [message] The message to display in the snackbar.