Skip to content

Commit 4f50db7

Browse files
fixup! TF-4684 Add drive card hover close button
1 parent 7714d76 commit 4f50db7

5 files changed

Lines changed: 19 additions & 26 deletions

File tree

core/lib/presentation/utils/html_transformer/dom/ensure_drive_card_delete_button_transformer.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ class EnsureDriveCardDeleteButtonTransformer extends DomTransformer {
2424
Map<String, String>? mapUrlDownloadCID,
2525
}) async {
2626
try {
27-
final cardsMissingButton = document
28-
.querySelectorAll('.tmail-drive-card')
29-
.where((card) => card.querySelector('.tmail-drive-card-delete') == null)
30-
.toList();
27+
final cards = document.querySelectorAll('.tmail-drive-card');
28+
if (cards.isEmpty) return;
3129

32-
if (cardsMissingButton.isEmpty) return;
30+
final cardsMissingButton = cards
31+
.where((card) => card.querySelector('.tmail-drive-card-delete') == null);
3332

3433
for (final card in cardsMissingButton) {
3534
card.append(Element.html(FileLinkCardHtmlBuilder.buildFileCardDeleteButton(

core/lib/presentation/utils/html_transformer/dom/remove_drive_card_delete_button_transformer.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class RemoveDriveCardDeleteButtonTransformer extends DomTransformer {
2121
final deleteButtonStyles = document.querySelectorAll('style')
2222
.where((style) => style.text.contains('.tmail-drive-card-delete'));
2323

24-
if (deleteButtons.isEmpty && deleteButtonStyles.isEmpty) return;
25-
26-
await Future.wait([
27-
...deleteButtons.map((element) async => element.remove()),
28-
...deleteButtonStyles.map((element) async => element.remove()),
29-
]);
24+
for (final element in deleteButtons) {
25+
element.remove();
26+
}
27+
for (final element in deleteButtonStyles) {
28+
element.remove();
29+
}
3030
} catch (e) {
3131
logWarning('$runtimeType::process:Exception = $e');
3232
}

core/lib/utils/html/file_link_card_html_builder.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,10 @@ class FileLinkCardHtmlBuilder {
103103
.tmail-drive-card:hover .tmail-drive-card-delete {
104104
opacity: 1 !important;
105105
}
106+
@media (hover: none), (pointer: coarse) {
107+
.tmail-drive-card .tmail-drive-card-delete {
108+
opacity: 1 !important;
109+
}
110+
}
106111
</style>''';
107112
}

lib/features/composer/presentation/manager/drive_attachment_handler.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ class DriveAttachmentHandler {
1313
/// without this class depending on `BuildUtils` directly.
1414
final bool requireHttps;
1515

16-
/// One [DriveAttachmentHandler] instance is bound per composer session
17-
/// (see `composer_bindings.dart`), so this flag is enough to ensure the
18-
/// delete-button `<style>` block is inserted only once even when the
19-
/// Drive picker is used multiple times in the same composer.
20-
bool _hasInsertedDeleteButtonStyle = false;
21-
2216
void handleDrivePickResult(
2317
List<DriveDocument> result, {
2418
required void Function(String html) insertHtml,
@@ -55,12 +49,7 @@ class DriveAttachmentHandler {
5549
)
5650
.nonNulls
5751
.join();
58-
final html = FileLinkCardHtmlBuilder.wrapFileCardsHtml(
59-
cards,
60-
includeStyle: !_hasInsertedDeleteButtonStyle,
61-
);
62-
if (cards.isNotEmpty) _hasInsertedDeleteButtonStyle = true;
63-
return html;
52+
return FileLinkCardHtmlBuilder.wrapFileCardsHtml(cards);
6453
}
6554

6655
String? _driveFileCard(

test/features/composer/presentation/manager/drive_attachment_handler_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void main() {
8181
expect(insertedHtml.first, contains('<style>'));
8282
});
8383

84-
test('Should NOT duplicate the delete-button style on a second Drive pick in the same composer session', () async {
84+
test('Should include the delete-button style on every Drive pick in the same composer session', () async {
8585
handler.handleDrivePickResult([
8686
linkDoc,
8787
], insertHtml: (html) => insertedHtml.add(html), appLocalizations: appLocalizations);
@@ -91,10 +91,10 @@ void main() {
9191

9292
expect(insertedHtml, hasLength(2));
9393
expect(insertedHtml.first, contains('<style>'));
94-
expect(insertedHtml.last, isNot(contains('<style>')));
94+
expect(insertedHtml.last, contains('<style>'));
9595
});
9696

97-
test('Should still omit the style on a pick with no insertable docs, without consuming the "first insert" slot', () async {
97+
test('Should omit the style on a pick with no insertable docs, and still include it on the next pick', () async {
9898
handler.handleDrivePickResult([
9999
noLinkDoc,
100100
], insertHtml: (html) => insertedHtml.add(html), appLocalizations: appLocalizations);

0 commit comments

Comments
 (0)