## Summary - Each email row in the **Undo Log Detail** "Emails" section is now tappable. - Tapping resolves the email via `EmailRepository.findEmailByMessageId(accountId, messageId)` and navigates to its **current** location, so the link survives the move/snooze that changed its IMAP UID. - If the email has no Message-ID, or no row matches the lookup (e.g. hard-deleted), a SnackBar explains the situation instead of navigating. A `chevron_right` trailing icon was added to signal the rows are now navigable. Closes #474 ## Test plan - [x] New widget test `test/widget/undo_log_detail_screen_test.dart` covers: - tap on a row whose lookup hits → navigates to `/accounts/<acc>/mailboxes/<encoded>/emails/<encoded>` with the **current** mailbox/id - tap when lookup returns `null` → "Email no longer exists" SnackBar, no navigation - tap when the original row has no Message-ID → "no Message-ID" SnackBar, no navigation Co-authored-by: guettli <guettli@noreply.codeberg.org> Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/547
This commit was merged in pull request #547.
This commit is contained in:
committed by
guettli
co-authored by
guettli
parent
de2b9d22b4
commit
f1f7de7b4d
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:sharedinbox/core/models/email.dart';
|
||||
import 'package:sharedinbox/core/models/undo_action.dart';
|
||||
@@ -93,7 +94,9 @@ class UndoLogDetailScreen extends ConsumerWidget {
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
...action.originalEmails.map((email) => _EmailTile(email: email)),
|
||||
...action.originalEmails.map(
|
||||
(email) => _EmailTile(email: email, accountId: action.accountId),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -120,13 +123,14 @@ class _SectionHeader extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _EmailTile extends StatelessWidget {
|
||||
const _EmailTile({required this.email});
|
||||
class _EmailTile extends ConsumerWidget {
|
||||
const _EmailTile({required this.email, required this.accountId});
|
||||
|
||||
final Email email;
|
||||
final String accountId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final sender = email.from.isNotEmpty
|
||||
? (email.from.first.name ?? email.from.first.email)
|
||||
: '(Unknown Sender)';
|
||||
@@ -134,6 +138,43 @@ class _EmailTile extends StatelessWidget {
|
||||
leading: const Icon(Icons.email_outlined),
|
||||
title: Text(email.subject ?? '(No Subject)'),
|
||||
subtitle: Text(sender, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _openEmail(context, ref),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openEmail(BuildContext context, WidgetRef ref) async {
|
||||
final messageId = email.messageId;
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
if (messageId == null) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
duration: Duration(seconds: 5),
|
||||
content: Text('Cannot locate this email — no Message-ID.'),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final found = await ref
|
||||
.read(emailRepositoryProvider)
|
||||
.findEmailByMessageId(accountId, messageId);
|
||||
if (!context.mounted) return;
|
||||
if (found == null) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
duration: Duration(seconds: 5),
|
||||
content: Text(
|
||||
'Email no longer exists at its previous location. '
|
||||
'Use Undo to restore it.',
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
context.go(
|
||||
'/accounts/$accountId'
|
||||
'/mailboxes/${Uri.encodeComponent(found.mailboxPath)}'
|
||||
'/emails/${Uri.encodeComponent(found.id)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user