diff --git a/analyze_out_new.txt b/analyze_out_new.txt new file mode 100644 index 0000000..41c1fd3 Binary files /dev/null and b/analyze_out_new.txt differ diff --git a/lib/constants/colours.dart b/lib/constants/colours.dart index 7dc0774..eb49db7 100644 --- a/lib/constants/colours.dart +++ b/lib/constants/colours.dart @@ -104,6 +104,13 @@ final functionsBackgroundColor = Colors.white; const instructionsBarColor = Colors.transparent; const instructionsUnselectedColor = Colors.grey; +<<<<<<< feature/delete-all-history-65 +const border = Color(0xFFF5E0C8); + +/// A color for error messages or destructive actions. +const error = Colors.redAccent; +======= final historyIncidentalColor = Colors.grey[600]; const historyDeleteColor = Colors.redAccent; final historyNoneColor = Colors.grey.withValues(alpha: 0.5); +>>>>>>> dev diff --git a/lib/widgets/history.dart b/lib/widgets/history.dart index 617b8ed..846022d 100644 --- a/lib/widgets/history.dart +++ b/lib/widgets/history.dart @@ -36,6 +36,7 @@ import 'package:solidui/solidui.dart'; import 'package:innerpod/constants/colours.dart'; import 'package:innerpod/utils/session_logic.dart'; +import 'package:innerpod/constants/colours.dart' as colours; class History extends StatefulWidget { const History({super.key}); @@ -139,6 +140,8 @@ class _HistoryState extends State { ElevatedButton( onPressed: () => Navigator.pop(context, true), style: ElevatedButton.styleFrom( + backgroundColor: colours.error.withValues(alpha: 0.1), + foregroundColor: colours.error, elevation: 0, ), child: const Text('Delete'), @@ -181,6 +184,70 @@ class _HistoryState extends State { } } + Future _deleteAllSessions() async { + final confirmed = await showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Delete All Sessions'), + content: const Text( + 'Are you sure you want to delete ALL sessions? This action cannot be undone.', + style: TextStyle(fontSize: 16), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + ElevatedButton( + onPressed: () => Navigator.pop(context, true), + style: ElevatedButton.styleFrom( + backgroundColor: colours.error.withValues(alpha: 0.1), + foregroundColor: colours.error, + elevation: 0, + ), + child: const Text('Delete All'), + ), + ], + ), + ); + + if (confirmed == true) { + await _performDeleteAll(); + } + } + + Future _performDeleteAll() async { + setState(() => _isLoading = true); + try { + final newContent = serializeSessions([]); + await writePod( + 'sessions.ttl', + newContent, + overwrite: true, + ); + await _loadSessions(); + } on SecurityKeyNotAvailableException { + debugPrint( + 'Security key missing - cannot write sessions.ttl for bulk deletion', + ); + if (mounted) { + await getKeyFromUserIfRequired(context, widget); + if (mounted) { + await _performDeleteAll(); + } + } + } catch (e) { + debugPrint('Error deleting all sessions: $e'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to delete all sessions: $e')), + ); + } + } finally { + if (mounted) setState(() => _isLoading = false); + } + } + Future _editSession(Map session) async { final titleController = TextEditingController(text: session['title']); final descriptionController = @@ -278,8 +345,18 @@ class _HistoryState extends State { title: const Text('Session History'), automaticallyImplyLeading: false, // Don't show back button actions: [ + if (_sessions.isNotEmpty) + IconButton( + icon: const Icon( + Icons.delete_sweep_outlined, + color: colours.error, + ), + tooltip: 'Delete all sessions', + onPressed: _deleteAllSessions, + ), IconButton( icon: const Icon(Icons.refresh), + tooltip: 'Refresh', onPressed: _loadSessions, ), const SizedBox(width: 8), @@ -407,7 +484,11 @@ class _HistoryState extends State { icon: const Icon( Icons.delete_outline, size: 20, +<<<<<<< feature/delete-all-history-65 + color: colours.error, +======= color: historyDeleteColor, +>>>>>>> dev ), onPressed: () => _deleteSession(session['rawStart']!),