🐛 Bug fixes on edit content truncated post

This commit is contained in:
LittleSheep 2024-10-14 23:04:55 +08:00
parent 063c087089
commit 59c4d667f6
2 changed files with 57 additions and 24 deletions

View File

@ -4,8 +4,13 @@ import 'package:gap/gap.dart';
class LoadingIndicator extends StatefulWidget { class LoadingIndicator extends StatefulWidget {
final bool isActive; final bool isActive;
final Color? backgroundColor;
const LoadingIndicator({super.key, this.isActive = true}); const LoadingIndicator({
super.key,
this.isActive = true,
this.backgroundColor,
});
@override @override
State<LoadingIndicator> createState() => _LoadingIndicatorState(); State<LoadingIndicator> createState() => _LoadingIndicatorState();
@ -63,7 +68,7 @@ class _LoadingIndicatorState extends State<LoadingIndicator>
axisAlignment: -1, // Align animation from the top axisAlignment: -1, // Align animation from the top
child: Container( child: Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24), padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
color: color: widget.backgroundColor ??
Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5), Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,

View File

@ -11,6 +11,7 @@ import 'package:solian/exts.dart';
import 'package:solian/models/post.dart'; import 'package:solian/models/post.dart';
import 'package:solian/platform.dart'; import 'package:solian/platform.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/posts.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/screens/posts/post_editor.dart'; import 'package:solian/screens/posts/post_editor.dart';
import 'package:solian/widgets/loading_indicator.dart'; import 'package:solian/widgets/loading_indicator.dart';
@ -28,20 +29,14 @@ class PostAction extends StatefulWidget {
} }
class _PostActionState extends State<PostAction> { class _PostActionState extends State<PostAction> {
bool _isBusy = true; bool _isBusy = false;
bool _canModifyContent = false; bool _canModifyContent = false;
void _checkAbleToModifyContent() async { void _checkAbleToModifyContent() async {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (auth.isAuthorized.isFalse) return; if (auth.isAuthorized.isFalse) return;
setState(() => _isBusy = true); _canModifyContent = auth.userProfile.value!['id'] == widget.item.author.id;
setState(() {
_canModifyContent =
auth.userProfile.value!['id'] == widget.item.author.id;
_isBusy = false;
});
} }
Future<void> _doShare({bool noUri = false}) async { Future<void> _doShare({bool noUri = false}) async {
@ -94,6 +89,8 @@ class _PostActionState extends State<PostAction> {
: List.empty(); : List.empty();
final hasMultipleAttachment = attachments.length > 1; final hasMultipleAttachment = attachments.length > 1;
setState(() => _isBusy = true);
final screenshot = ScreenshotController(); final screenshot = ScreenshotController();
final image = await screenshot.captureFromLongWidget( final image = await screenshot.captureFromLongWidget(
MediaQuery( MediaQuery(
@ -137,6 +134,21 @@ class _PostActionState extends State<PostAction> {
); );
context.showSnackbar('fileSavedAt'.trParams({'path': filepath})); context.showSnackbar('fileSavedAt'.trParams({'path': filepath}));
} }
setState(() => _isBusy = false);
}
Future<Post> _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 @override
@ -182,7 +194,13 @@ class _PostActionState extends State<PostAction> {
), ),
], ],
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16), ).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( Expanded(
child: ListView( child: ListView(
children: [ children: [
@ -205,10 +223,12 @@ class _PostActionState extends State<PostAction> {
IconButton( IconButton(
icon: const Icon(Icons.image), icon: const Icon(Icons.image),
tooltip: 'shareImage'.tr, tooltip: 'shareImage'.tr,
onPressed: () async { onPressed: _isBusy
await _shareImage(); ? null
Navigator.pop(context); : () async {
}, await _shareImage();
Navigator.pop(context);
},
), ),
], ],
), ),
@ -288,15 +308,23 @@ class _PostActionState extends State<PostAction> {
contentPadding: const EdgeInsets.symmetric(horizontal: 24), contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: const Icon(Icons.edit), leading: const Icon(Icons.edit),
title: Text('edit'.tr), title: Text('edit'.tr),
onTap: () async { onTap: _isBusy
Navigator.pop( ? null
context, : () async {
AppRouter.instance.pushNamed( setState(() => _isBusy = true);
'postEditor', var item = widget.item;
extra: PostPublishArguments(edit: 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) if (_canModifyContent)
ListTile( ListTile(