π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add loading state to comment send button to prevent duplicate sends
ashilkn29c755d89096
diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dartindex e627c31c63..233fc947cc 100644--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart@@ -13,6 +13,7 @@ import "package:photos/models/social/reaction.dart";import "package:photos/models/social/social_data_provider.dart";import "package:photos/services/collections_service.dart";import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/components/buttons/icon_button_widget.dart";import "package:photos/ui/notification/toast.dart";import "package:photos/ui/social/widgets/collection_selector_widget.dart";@@ -45,6 +46,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {Comment? _replyingTo;bool _isLoading = true;bool _isLoadingMore = false;+ bool _isSending = false;bool _hasMoreComments = true;int _offset = 0;final Map<int, User> _userCache = {};@@ -329,7 +331,9 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {Future<void> _sendComment() async {final text = _textController.text.trim();- if (text.isEmpty) return;+ if (text.isEmpty || _isSending) return;++ setState(() => _isSending = true);try {final result = await SocialDataProvider.instance.addComment(@@ -372,6 +376,10 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {if (mounted) {showShortToast(context, "Failed to send comment");}+ } finally {+ if (mounted) {+ setState(() => _isSending = false);+ }}}@@ -451,7 +459,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {onTap: () => FocusScope.of(context).unfocus(),behavior: HitTestBehavior.translucent,child: _isLoading- ? const Center(child: CircularProgressIndicator())+ ? const EnteLoadingWidget(): ListView.builder(controller: _scrollController,reverse: true,@@ -517,6 +525,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {controller: _textController,focusNode: _inputFocusNode,onSend: _sendComment,+ isSending: _isSending,),],),diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dartindex c1fa9b2822..a5a5c6eb0b 100644--- a/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dart+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_input_widget.dart@@ -3,6 +3,7 @@ import "package:flutter/services.dart";import "package:photos/models/api/collection/user.dart";import "package:photos/models/social/comment.dart";import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/social/widgets/reply_preview_widget.dart";class CommentInputWidget extends StatefulWidget {@@ -13,6 +14,7 @@ class CommentInputWidget extends StatefulWidget {final TextEditingController controller;final FocusNode focusNode;final VoidCallback onSend;+ final bool isSending;const CommentInputWidget({this.replyingTo,@@ -22,6 +24,7 @@ class CommentInputWidget extends StatefulWidget {required this.controller,required this.focusNode,required this.onSend,+ this.isSending = false,super.key,});@@ -151,13 +154,30 @@ class _CommentInputWidgetState extends State<CommentInputWidget>horizontal: 18,vertical: 14,),- suffixIcon: IconButton(- onPressed: widget.onSend,- icon: Icon(- Icons.send_rounded,- color: colorScheme.textBase.withValues(alpha: 0.8),- size: 24,- ),+ suffixIcon: AnimatedSwitcher(+ duration: const Duration(milliseconds: 200),+ switchInCurve: Curves.easeOut,+ switchOutCurve: Curves.easeOut,+ child: widget.isSending+ ? const Padding(+ key: ValueKey('loading'),+ padding: EdgeInsets.all(12),+ child: SizedBox(+ width: 24,+ height: 24,+ child: EnteLoadingWidget(size: 20, padding: 0),+ ),+ )+ : IconButton(+ key: const ValueKey('send'),+ onPressed: widget.onSend,+ icon: Icon(+ Icons.send_rounded,+ color:+ colorScheme.textBase.withValues(alpha: 0.8),+ size: 24,+ ),+ ),),enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(20),