refactor: extract _batchMoveToRole helper in email_list_screen

_batchArchive and _batchMarkSpam shared identical role-lookup+move logic;
collapsed into a single _batchMoveToRole(role, notFoundMessage) helper.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Thomas Güttler
2026-04-24 16:32:22 +02:00
co-authored by Claude Sonnet 4.6
parent e3ba18285d
commit d1f77d3eb6
3 changed files with 17 additions and 28 deletions
+6
View File
@@ -6,6 +6,12 @@ Tasks get moved from NEXT.md to DONE.md
## Tasks
## Extract _batchMoveToRole helper in email_list_screen
`_batchArchive()` and `_batchMarkSpam()` collapsed into a shared
`_batchMoveToRole(role, notFoundMessage)` helper, eliminating ~20 lines of
duplication.
## Enable always_use_package_imports lint rule
Added rule to `analysis_options.yaml`; `dart fix --apply` converted 125 relative
-4
View File
@@ -18,10 +18,6 @@ Then commit.
## Tasks
## Extract _batchMoveToRole helper in email_list_screen
`_batchArchive()` and `_batchMarkSpam()` in `lib/ui/screens/email_list_screen.dart` (~lines 249313) share the same pattern: look up a mailbox role, validate, iterate selected ids, call repo method. Extract a shared `_batchMoveToRole(String role)` helper.
## Extract _tryConnection logic into shared mixin for account screens
`add_account_screen.dart` and `edit_account_screen.dart` duplicate the `_tryConnection()` method and the `_tryTesting`/`_tryOk`/`_tryErr` state triplet. Extract into a shared mixin or base widget.
+11 -24
View File
@@ -246,25 +246,28 @@ class _EmailListScreenState extends ConsumerState<EmailListScreen> {
);
}
Future<void> _batchArchive() async {
Future<void> _batchMoveToRole(String role, String notFoundMessage) async {
final ids = _selectedEmailIds;
_clearSelection();
final archive = await ref
final mailbox = await ref
.read(mailboxRepositoryProvider)
.findMailboxByRole(widget.accountId, 'archive');
.findMailboxByRole(widget.accountId, role);
if (!mounted) return;
if (archive == null) {
if (mailbox == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('No archive folder found')),
SnackBar(content: Text(notFoundMessage)),
);
return;
}
final repo = ref.read(emailRepositoryProvider);
for (final id in ids) {
await repo.moveEmail(id, archive.path);
await repo.moveEmail(id, mailbox.path);
}
}
Future<void> _batchArchive() =>
_batchMoveToRole('archive', 'No archive folder found');
Future<void> _batchDelete() async {
final ids = _selectedEmailIds;
final count = ids.length;
@@ -293,24 +296,8 @@ class _EmailListScreenState extends ConsumerState<EmailListScreen> {
}
}
Future<void> _batchMarkSpam() async {
final ids = _selectedEmailIds;
_clearSelection();
final junk = await ref
.read(mailboxRepositoryProvider)
.findMailboxByRole(widget.accountId, 'junk');
if (!mounted) return;
if (junk == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('No spam folder found')),
);
return;
}
final repo = ref.read(emailRepositoryProvider);
for (final id in ids) {
await repo.moveEmail(id, junk.path);
}
}
Future<void> _batchMarkSpam() =>
_batchMoveToRole('junk', 'No spam folder found');
Future<void> _batchMove() async {
final ids = _selectedEmailIds;