Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add delete comment functionality with confirmation dialog

ashilkn96f6a8fe6759
diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_actions_popup.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_actions_popup.dart
index 7313c527b0..d4d6f0d52e 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/comment_actions_popup.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_actions_popup.dart
@@ -5,11 +5,15 @@ class CommentActionsPopup extends StatelessWidget {
final bool isLiked;
final VoidCallback onLikeTap;
final VoidCallback onReplyTap;
+ final VoidCallback? onDeleteTap;
+ final bool showDelete;
const CommentActionsPopup({
required this.isLiked,
required this.onLikeTap,
required this.onReplyTap,
+ this.onDeleteTap,
+ this.showDelete = true,
super.key,
});
@@ -53,16 +57,17 @@ class CommentActionsPopup extends StatelessWidget {
),
defaultIconColor: colorScheme.textBase,
),
- _ActionItem(
- icon: Icons.delete_outline_rounded,
- label: "Delete",
- onTap: () {},
- textStyle: textTheme.mini.copyWith(
- height: 19 / 12,
- letterSpacing: -0.36,
+ if (showDelete)
+ _ActionItem(
+ icon: Icons.delete_outline_rounded,
+ label: "Delete",
+ onTap: onDeleteTap!,
+ textStyle: textTheme.mini.copyWith(
+ height: 19 / 12,
+ letterSpacing: -0.36,
+ ),
+ defaultIconColor: colorScheme.textBase,
),
- defaultIconColor: colorScheme.textBase,
- ),
],
),
),
diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
index 0a09bcf8f5..0a4779b10d 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
@@ -1,5 +1,6 @@
import "package:flutter/material.dart";
import "package:flutter/services.dart";
+import "package:logging/logging.dart";
import "package:photos/extensions/user_extension.dart";
import "package:photos/models/api/collection/user.dart";
import "package:photos/models/social/comment.dart";
@@ -7,11 +8,15 @@ import "package:photos/models/social/reaction.dart";
import "package:photos/models/social/social_data_provider.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
import "package:photos/ui/social/widgets/comment_actions_capsule.dart";
import "package:photos/ui/social/widgets/comment_actions_popup.dart";
+import "package:photos/ui/social/widgets/delete_comment_confirmation_dialog.dart";
import "package:photos/utils/social/relative_time_formatter.dart";
+final _logger = Logger("CommentBubbleWidget");
+
class CommentBubbleWidget extends StatefulWidget {
final Comment comment;
final User user;
@@ -22,6 +27,7 @@ class CommentBubbleWidget extends StatefulWidget {
final Future<List<Reaction>> Function() onFetchReactions;
final VoidCallback onReplyTap;
final User Function(Comment) userResolver;
+ final VoidCallback? onCommentDeleted;
const CommentBubbleWidget({
required this.comment,
@@ -33,6 +39,7 @@ class CommentBubbleWidget extends StatefulWidget {
required this.onFetchReactions,
required this.onReplyTap,
required this.userResolver,
+ this.onCommentDeleted,
super.key,
});
@@ -150,6 +157,28 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>
if (mounted) _overlayController.hide();
}
+ Future<void> _handleDelete() async {
+ await _hideHighlight();
+ if (!mounted) return;
+
+ final confirmed = await showDeleteCommentConfirmationDialog(context);
+
+ if (confirmed == true) {
+ try {
+ await SocialDataProvider.instance.deleteComment(widget.comment.id);
+ if (mounted) {
+ showShortToast(context, "Comment deleted");
+ widget.onCommentDeleted?.call();
+ }
+ } catch (e) {
+ _logger.severe("Failed to delete comment", e);
+ if (mounted) {
+ showShortToast(context, "Failed to delete comment");
+ }
+ }
+ }
+ }
+
@override
Widget build(BuildContext context) {
return CompositedTransformTarget(
@@ -313,6 +342,8 @@ class _CommentBubbleWidgetState extends State<CommentBubbleWidget>
_hideHighlight();
widget.onReplyTap();
},
+ onDeleteTap: _handleDelete,
+ showDelete: widget.isOwnComment,
),
),
],
diff --git a/mobile/apps/photos/lib/ui/social/widgets/delete_comment_confirmation_dialog.dart b/mobile/apps/photos/lib/ui/social/widgets/delete_comment_confirmation_dialog.dart
new file mode 100644
index 0000000000..03e7b45ce1
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/social/widgets/delete_comment_confirmation_dialog.dart
@@ -0,0 +1,91 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/common/gradient_button.dart";
+
+/// Shows a bottom sheet confirmation dialog for deleting a comment.
+/// Returns true if confirmed, null if cancelled.
+Future<bool?> showDeleteCommentConfirmationDialog(BuildContext context) {
+ return showModalBottomSheet<bool>(
+ context: context,
+ isScrollControlled: true,
+ isDismissible: true,
+ builder: (context) => const _DeleteCommentConfirmationSheet(),
+ );
+}
+
+class _DeleteCommentConfirmationSheet extends StatelessWidget {
+ const _DeleteCommentConfirmationSheet();
+
+ @override
+ Widget build(BuildContext context) {
+ final textTheme = getEnteTextTheme(context);
+ final colorScheme = getEnteColorScheme(context);
+
+ return Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backdropBase,
+ border: Border(top: BorderSide(color: colorScheme.strokeFaint)),
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(24),
+ topRight: Radius.circular(24),
+ ),
+ ),
+ child: SafeArea(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const SizedBox(height: 8),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Container(
+ decoration: BoxDecoration(
+ borderRadius: BorderRadius.circular(50),
+ color: colorScheme.backgroundElevated,
+ ),
+ padding: const EdgeInsets.all(8),
+ child: Icon(
+ Icons.close,
+ size: 24,
+ color: colorScheme.textBase,
+ ),
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ Text(
+ "Delete comment?",
+ style: textTheme.h3Bold,
+ textAlign: TextAlign.center,
+ ),
+ const SizedBox(height: 12),
+ Text(
+ "This comment will be permanently deleted.",
+ style: textTheme.body.copyWith(color: colorScheme.textMuted),
+ textAlign: TextAlign.center,
+ ),
+ const SizedBox(height: 24),
+ SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ onTap: () => Navigator.of(context).pop(true),
+ text: "Delete",
+ linearGradientColors: [
+ colorScheme.warning400,
+ colorScheme.warning400,
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}