From 3a82119c2a21e0b83a98e82154512bf1d81a6112 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Tue, 31 Mar 2026 10:31:59 +0200 Subject: [PATCH] fix: library action confirmation and snackbar feedback --- lib/screens/libraries/libraries_screen.dart | 86 ++++++++++----------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/lib/screens/libraries/libraries_screen.dart b/lib/screens/libraries/libraries_screen.dart index 328db280..22af880e 100644 --- a/lib/screens/libraries/libraries_screen.dart +++ b/lib/screens/libraries/libraries_screen.dart @@ -587,7 +587,41 @@ class _LibrariesScreenState extends State ]; } - void _handleLibraryMenuAction(String action, PlexLibrary library) { + Future _handleLibraryMenuAction(String action, PlexLibrary library) async { + // Find the menu item for confirmation details + final menuItems = _getLibraryMenuItems(library); + final item = menuItems.where((i) => i.value == action).firstOrNull; + if (item == null) return; + + if (item.requiresConfirmation) { + final confirmed = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text(item.confirmationTitle ?? t.dialog.confirmAction), + content: Text(item.confirmationMessage ?? t.libraries.confirmActionMessage), + actions: [ + FocusableButton( + autofocus: true, + onPressed: () => Navigator.pop(context, false), + child: TextButton( + onPressed: () => Navigator.pop(context, false), + child: Text(t.common.cancel), + ), + ), + FocusableButton( + onPressed: () => Navigator.pop(context, true), + child: TextButton( + onPressed: () => Navigator.pop(context, true), + style: item.isDestructive ? TextButton.styleFrom(foregroundColor: Colors.red) : null, + child: Text(t.common.confirm), + ), + ), + ], + ), + ); + if (confirmed != true) return; + } + switch (action) { case 'scan': _scanLibrary(library); @@ -1183,9 +1217,9 @@ class _LibraryManagementSheetState extends State<_LibraryManagementSheet> { widget.onReorder(_tempLibraries); } - Future _showLibraryMenuBottomSheet(BuildContext outerContext, PlexLibrary library) async { + void _showLibraryMenuBottomSheet(BuildContext outerContext, PlexLibrary library) { final menuItems = widget.getLibraryMenuItems(library); - final selected = await OverlaySheetController.pushAdaptive( + OverlaySheetController.pushAdaptive( outerContext, builder: (context) => SafeArea( child: Column( @@ -1199,52 +1233,18 @@ class _LibraryManagementSheetState extends State<_LibraryManagementSheet> { (entry) => ListTile( leading: AppIcon(entry.$2.icon, fill: 1), title: Text(entry.$2.label), - onTap: () => OverlaySheetController.popAdaptive(context, entry.$2.value), + onTap: () { + // Close the entire overlay sheet, then let the parent handle + // confirmation and execution (parent state is always mounted) + OverlaySheetController.closeAdaptive(context); + widget.onLibraryMenuAction(entry.$2.value, library); + }, ), ), ], ), ), ); - - if (selected != null && mounted) { - // Find the selected item to check if confirmation is needed - final selectedItem = menuItems.where((item) => item.value == selected).firstOrNull; - if (selectedItem == null) return; - - if (selectedItem.requiresConfirmation) { - if (!mounted || !context.mounted) return; - final confirmed = await showDialog( - context: context, - builder: (context) => AlertDialog( - title: Text(selectedItem.confirmationTitle ?? t.dialog.confirmAction), - content: Text(selectedItem.confirmationMessage ?? t.libraries.confirmActionMessage), - actions: [ - FocusableButton( - autofocus: true, - onPressed: () => Navigator.pop(context, false), - child: TextButton( - onPressed: () => Navigator.pop(context, false), - child: Text(t.common.cancel), - ), - ), - FocusableButton( - onPressed: () => Navigator.pop(context, true), - child: TextButton( - onPressed: () => Navigator.pop(context, true), - style: selectedItem.isDestructive ? TextButton.styleFrom(foregroundColor: Colors.red) : null, - child: Text(t.common.confirm), - ), - ), - ], - ), - ); - - if (confirmed != true) return; - } - - widget.onLibraryMenuAction(selected, library); - } } /// Get set of library names that appear more than once (not globally unique)