From 59c4d667f69c4d80ce19dce1e70375630a052815 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 14 Oct 2024 23:04:55 +0800 Subject: [PATCH] :bug: Bug fixes on edit content truncated post --- lib/widgets/loading_indicator.dart | 9 +++- lib/widgets/posts/post_action.dart | 72 +++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/lib/widgets/loading_indicator.dart b/lib/widgets/loading_indicator.dart index ea137c9..91c9686 100644 --- a/lib/widgets/loading_indicator.dart +++ b/lib/widgets/loading_indicator.dart @@ -4,8 +4,13 @@ import 'package:gap/gap.dart'; class LoadingIndicator extends StatefulWidget { final bool isActive; + final Color? backgroundColor; - const LoadingIndicator({super.key, this.isActive = true}); + const LoadingIndicator({ + super.key, + this.isActive = true, + this.backgroundColor, + }); @override State createState() => _LoadingIndicatorState(); @@ -63,7 +68,7 @@ class _LoadingIndicatorState extends State axisAlignment: -1, // Align animation from the top child: Container( padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24), - color: + color: widget.backgroundColor ?? Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5), child: Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/widgets/posts/post_action.dart b/lib/widgets/posts/post_action.dart index 9bae3e2..71bc5d3 100644 --- a/lib/widgets/posts/post_action.dart +++ b/lib/widgets/posts/post_action.dart @@ -11,6 +11,7 @@ import 'package:solian/exts.dart'; import 'package:solian/models/post.dart'; import 'package:solian/platform.dart'; import 'package:solian/providers/auth.dart'; +import 'package:solian/providers/content/posts.dart'; import 'package:solian/router.dart'; import 'package:solian/screens/posts/post_editor.dart'; import 'package:solian/widgets/loading_indicator.dart'; @@ -28,20 +29,14 @@ class PostAction extends StatefulWidget { } class _PostActionState extends State { - bool _isBusy = true; + bool _isBusy = false; bool _canModifyContent = false; void _checkAbleToModifyContent() async { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; - setState(() => _isBusy = true); - - setState(() { - _canModifyContent = - auth.userProfile.value!['id'] == widget.item.author.id; - _isBusy = false; - }); + _canModifyContent = auth.userProfile.value!['id'] == widget.item.author.id; } Future _doShare({bool noUri = false}) async { @@ -94,6 +89,8 @@ class _PostActionState extends State { : List.empty(); final hasMultipleAttachment = attachments.length > 1; + setState(() => _isBusy = true); + final screenshot = ScreenshotController(); final image = await screenshot.captureFromLongWidget( MediaQuery( @@ -137,6 +134,21 @@ class _PostActionState extends State { ); context.showSnackbar('fileSavedAt'.trParams({'path': filepath})); } + + setState(() => _isBusy = false); + } + + Future _getFullPost() async { + final PostProvider posts = Get.find(); + + try { + final resp = await posts.getPost(widget.item.id.toString()); + return Post.fromJson(resp.body); + } catch (e) { + context.showErrorDialog(e).then((_) => Navigator.pop(context)); + } + + return widget.item; } @override @@ -182,7 +194,13 @@ class _PostActionState extends State { ), ], ).paddingOnly(left: 24, right: 24, top: 32, bottom: 16), - LoadingIndicator(isActive: _isBusy), + LoadingIndicator( + isActive: _isBusy, + backgroundColor: Theme.of(context) + .colorScheme + .surfaceContainerHigh + .withOpacity(0.5), + ), Expanded( child: ListView( children: [ @@ -205,10 +223,12 @@ class _PostActionState extends State { IconButton( icon: const Icon(Icons.image), tooltip: 'shareImage'.tr, - onPressed: () async { - await _shareImage(); - Navigator.pop(context); - }, + onPressed: _isBusy + ? null + : () async { + await _shareImage(); + Navigator.pop(context); + }, ), ], ), @@ -288,15 +308,23 @@ class _PostActionState extends State { contentPadding: const EdgeInsets.symmetric(horizontal: 24), leading: const Icon(Icons.edit), title: Text('edit'.tr), - onTap: () async { - Navigator.pop( - context, - AppRouter.instance.pushNamed( - 'postEditor', - extra: PostPublishArguments(edit: widget.item), - ), - ); - }, + onTap: _isBusy + ? null + : () async { + setState(() => _isBusy = true); + var item = widget.item; + if (item.body?['content_truncated'] == true) { + item = await _getFullPost(); + } + Navigator.pop( + context, + AppRouter.instance.pushNamed( + 'postEditor', + extra: PostPublishArguments(edit: item), + ), + ); + if (mounted) setState(() => _isBusy = false); + }, ), if (_canModifyContent) ListTile(