π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add error state and scale animation to comment send button
ashilkn6bbe4f52b201
diff --git a/mobile/apps/photos/lib/ui/social/comments_screen.dart b/mobile/apps/photos/lib/ui/social/comments_screen.dartindex 233fc947cc..889b843b42 100644--- a/mobile/apps/photos/lib/ui/social/comments_screen.dart+++ b/mobile/apps/photos/lib/ui/social/comments_screen.dart@@ -46,7 +46,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {Comment? _replyingTo;bool _isLoading = true;bool _isLoadingMore = false;- bool _isSending = false;+ SendButtonState _sendState = SendButtonState.idle;bool _hasMoreComments = true;int _offset = 0;final Map<int, User> _userCache = {};@@ -331,9 +331,9 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {Future<void> _sendComment() async {final text = _textController.text.trim();- if (text.isEmpty || _isSending) return;+ if (text.isEmpty || _sendState != SendButtonState.idle) return;- setState(() => _isSending = true);+ setState(() => _sendState = SendButtonState.sending);try {final result = await SocialDataProvider.instance.addComment(@@ -344,15 +344,14 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {);if (result == null) {_logger.warning('Failed to save comment');- if (mounted) {- showShortToast(context, "Failed to send comment");- }+ _showSendError();return;}// Update UI only after successful persistenceif (mounted) {setState(() {+ _sendState = SendButtonState.idle;_comments.insert(0, result);_replyingTo = null;@@ -373,16 +372,22 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {}} catch (e) {_logger.severe('Failed to send comment', e);- if (mounted) {- showShortToast(context, "Failed to send comment");- }- } finally {- if (mounted) {- setState(() => _isSending = false);- }+ _showSendError();}}+ void _showSendError() {+ if (!mounted) return;+ setState(() => _sendState = SendButtonState.error);+ showShortToast(context, "Failed to send comment");++ Future.delayed(const Duration(milliseconds: 1500), () {+ if (mounted && _sendState == SendButtonState.error) {+ setState(() => _sendState = SendButtonState.idle);+ }+ });+ }+void _handleCommentDeleted(String commentId) {Bus.instance.fire(CommentDeletedEvent(commentId));setState(() {@@ -525,7 +530,7 @@ class _FileCommentsScreenState extends State<FileCommentsScreen> {controller: _textController,focusNode: _inputFocusNode,onSend: _sendComment,- isSending: _isSending,+ sendState: _sendState,),],),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 a5a5c6eb0b..4418f8146c 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@@ -6,6 +6,8 @@ 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";+enum SendButtonState { idle, sending, error }+class CommentInputWidget extends StatefulWidget {final Comment? replyingTo;final User? replyingToUser;@@ -14,7 +16,7 @@ class CommentInputWidget extends StatefulWidget {final TextEditingController controller;final FocusNode focusNode;final VoidCallback onSend;- final bool isSending;+ final SendButtonState sendState;const CommentInputWidget({this.replyingTo,@@ -24,7 +26,7 @@ class CommentInputWidget extends StatefulWidget {required this.controller,required this.focusNode,required this.onSend,- this.isSending = false,+ this.sendState = SendButtonState.idle,super.key,});@@ -158,26 +160,47 @@ class _CommentInputWidgetState extends State<CommentInputWidget>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,- ),+ transitionBuilder: (child, animation) {+ final curvedAnimation = CurvedAnimation(+ parent: animation,+ curve: Curves.easeInOutExpo,+ );+ final scale = Tween<double>(begin: 0.5, end: 1.0)+ .animate(curvedAnimation);+ return FadeTransition(+ opacity: curvedAnimation,+ child: ScaleTransition(scale: scale, child: child),+ );+ },+ child: switch (widget.sendState) {+ SendButtonState.sending => const Padding(+ key: ValueKey('loading'),+ padding: EdgeInsets.all(12),+ child: SizedBox(+ width: 24,+ height: 24,+ child: EnteLoadingWidget(size: 20, padding: 0),+ ),+ ),+ SendButtonState.error => Padding(+ key: const ValueKey('error'),+ padding: const EdgeInsets.all(12),+ child: Icon(+ Icons.error_outline,+ color: colorScheme.warning500,+ size: 24,+ ),+ ),+ SendButtonState.idle => 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),